mirror of
https://git.code.sf.net/p/quake/newtree
synced 2024-11-22 20:21:38 +00:00
Faster Cmd_TokenizeString - no malloc/free, just a static buffer.
This commit is contained in:
parent
4c49007a2b
commit
f8b0302ed6
1 changed files with 11 additions and 4 deletions
15
source/cmd.c
15
source/cmd.c
|
@ -583,11 +583,11 @@ Parses the given string into command line tokens.
|
|||
*/
|
||||
void Cmd_TokenizeString (char *text)
|
||||
{
|
||||
static char argv_buf[1024];
|
||||
int argv_idx;
|
||||
int i;
|
||||
|
||||
// clear the args from the last string
|
||||
for (i=0 ; i<cmd_argc ; i++)
|
||||
free (cmd_argv[i]);
|
||||
argv_idx = 0;
|
||||
|
||||
cmd_argc = 0;
|
||||
cmd_args = NULL;
|
||||
|
@ -618,8 +618,15 @@ void Cmd_TokenizeString (char *text)
|
|||
|
||||
if (cmd_argc < MAX_ARGS)
|
||||
{
|
||||
cmd_argv[cmd_argc] = malloc (strlen(com_token)+1);
|
||||
if (argv_idx + strlen(com_token) + 1 > 1024)
|
||||
{
|
||||
Con_Printf ("Cmd_TokenizeString: overflow\n");
|
||||
return;
|
||||
}
|
||||
cmd_argv[cmd_argc] = argv_buf + argv_idx;
|
||||
strcpy (cmd_argv[cmd_argc], com_token);
|
||||
argv_idx += strlen(com_token) + 1;
|
||||
|
||||
cmd_argc++;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue