mirror of
https://git.code.sf.net/p/quake/newtree
synced 2025-02-16 16:41:30 +00:00
Faster Cbuf_InsertText
This commit is contained in:
parent
01b0156d9d
commit
4c49007a2b
1 changed files with 30 additions and 0 deletions
30
source/cmd.c
30
source/cmd.c
|
@ -130,6 +130,7 @@ Adds a \n to the text
|
||||||
FIXME: actually change the command buffer to do less copying
|
FIXME: actually change the command buffer to do less copying
|
||||||
============
|
============
|
||||||
*/
|
*/
|
||||||
|
#if 0 // Tonik
|
||||||
void Cbuf_InsertText (char *text)
|
void Cbuf_InsertText (char *text)
|
||||||
{
|
{
|
||||||
char *temp;
|
char *temp;
|
||||||
|
@ -156,6 +157,35 @@ void Cbuf_InsertText (char *text)
|
||||||
free (temp);
|
free (temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
void Cbuf_InsertText (char *text)
|
||||||
|
{
|
||||||
|
int textlen;
|
||||||
|
|
||||||
|
textlen = strlen(text);
|
||||||
|
if (cmd_text.cursize + 1 + textlen >= cmd_text.maxsize)
|
||||||
|
{
|
||||||
|
Con_Printf ("Cbuf_InsertText: overflow\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cmd_text.cursize)
|
||||||
|
{
|
||||||
|
memcpy (cmd_text.data, text, textlen);
|
||||||
|
cmd_text.cursize = textlen;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move up to make room for inserted text
|
||||||
|
memmove (cmd_text.data + textlen + 1, cmd_text.data, cmd_text.cursize);
|
||||||
|
cmd_text.cursize += textlen + 1;
|
||||||
|
|
||||||
|
// Insert new text
|
||||||
|
memcpy (cmd_text.data, text, textlen);
|
||||||
|
cmd_text.data[textlen] = '\n';
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
extract_line(char *line)
|
extract_line(char *line)
|
||||||
|
|
Loading…
Reference in a new issue