int maxknownstrings;
int numknownstrings;
+ // this is updated whenever a string is removed or added
+ // (simple optimization of the free string search)
+ int firstfreeknownstring;
const char **knownstrings;
// all memory allocations related to this vm_prog (code, edicts, strings)
// new unknown engine string
if (developer.integer >= 3)
Con_Printf("new engine string %p\n", s);
- for (i = 0;i < prog->numknownstrings;i++)
+ for (i = prog->firstfreeknownstring;i < prog->numknownstrings;i++)
if (!prog->knownstrings[i])
break;
if (i >= prog->numknownstrings)
}
prog->numknownstrings++;
}
+ prog->firstfreeknownstring = i + 1;
prog->knownstrings[i] = s;
return -1 - i;
}
int i;
if (!bufferlength)
return 0;
- for (i = 0;i < prog->numknownstrings;i++)
+ for (i = prog->firstfreeknownstring;i < prog->numknownstrings;i++)
if (!prog->knownstrings[i])
break;
if (i >= prog->numknownstrings)
}
prog->numknownstrings++;
}
+ prog->firstfreeknownstring = i + 1;
prog->knownstrings[i] = PRVM_Alloc(bufferlength);
if (pointer)
*pointer = (char *)(prog->knownstrings[i]);
Host_Error("PRVM_FreeString: attempt to free a non-existent or already freed string\n");
PRVM_Free((char *)prog->knownstrings[num]);
prog->knownstrings[num] = NULL;
+ prog->firstfreeknownstring = min(prog->firstfreeknownstring, num);
}
else
Host_Error("PRVM_FreeString: invalid string offset %i\n", num);