mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
do the builtin function lookup at load time rather than runtime and store
the function address in the progs function descriptor. this will speed up calls to builtin functions, especially when ranges get introduced.
This commit is contained in:
parent
dfc83c1f5f
commit
595280decb
3 changed files with 30 additions and 19 deletions
|
@ -185,6 +185,11 @@ typedef struct {
|
|||
int binum;
|
||||
} builtin_t;
|
||||
|
||||
typedef struct {
|
||||
int first_statement;
|
||||
builtin_proc func;
|
||||
} bfunction_t;
|
||||
|
||||
ddef_t *PR_FindGlobal (progs_t *pr, const char *name);
|
||||
ddef_t *ED_GlobalAtOfs (progs_t *pr, int ofs);
|
||||
|
||||
|
|
|
@ -111,23 +111,34 @@ PR_FindBuiltin (progs_t *pr, const char *name)
|
|||
int
|
||||
PR_RelocateBuiltins (progs_t *pr)
|
||||
{
|
||||
int i;
|
||||
int i, ind;
|
||||
dfunction_t *func;
|
||||
builtin_t *bi;
|
||||
const char *bi_name;
|
||||
|
||||
for (i = 1; i < pr->progs->numfunctions; i++) {
|
||||
func = pr->pr_functions + i;
|
||||
if (func->first_statement)
|
||||
|
||||
if (func->first_statement > 0)
|
||||
continue;
|
||||
bi_name = PR_GetString (pr, func->s_name);
|
||||
bi = PR_FindBuiltin (pr, bi_name);
|
||||
if (!bi) {
|
||||
Sys_Printf ("PR_RelocateBuiltins: %s: undefined builtin %s\n",
|
||||
pr->progs_name, bi_name);
|
||||
|
||||
if (!func->first_statement) {
|
||||
bi_name = PR_GetString (pr, func->s_name);
|
||||
bi = PR_FindBuiltin (pr, bi_name);
|
||||
if (!bi) {
|
||||
Sys_Printf ("PR_RelocateBuiltins: %s: undefined builtin %s\n",
|
||||
pr->progs_name, bi_name);
|
||||
return 0;
|
||||
}
|
||||
func->first_statement = -bi->binum;
|
||||
}
|
||||
|
||||
ind = -func->first_statement;
|
||||
if (ind >= pr->numbuiltins || !(bi = pr->builtins[ind]) || !bi->proc) {
|
||||
Sys_Printf ("Bad builtin call number: %d\n", ind);
|
||||
return 0;
|
||||
}
|
||||
func->first_statement = -bi->binum;
|
||||
((bfunction_t *) func)->func = bi->proc;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -247,7 +247,7 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum)
|
|||
{
|
||||
int exitdepth, profile, startprofile;
|
||||
unsigned int pointer;
|
||||
dfunction_t *f, *newf;
|
||||
dfunction_t *f;
|
||||
dstatement_t *st;
|
||||
edict_t *ed;
|
||||
pr_type_t *ptr;
|
||||
|
@ -700,17 +700,12 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum)
|
|||
pr->pr_argc = st->op - OP_CALL0;
|
||||
if (!OPA.func_var)
|
||||
PR_RunError (pr, "NULL function");
|
||||
newf = &pr->pr_functions[OPA.func_var];
|
||||
if (newf->first_statement < 0) {
|
||||
// negative statements are built in functions
|
||||
int i = -newf->first_statement;
|
||||
|
||||
if (i >= pr->numbuiltins || !pr->builtins[i]
|
||||
|| !pr->builtins[i]->proc)
|
||||
PR_RunError (pr, "Bad builtin call number");
|
||||
pr->builtins[i]->proc (pr);
|
||||
f = &pr->pr_functions[OPA.func_var];
|
||||
// negative statements are built in functions
|
||||
if (f->first_statement < 0) {
|
||||
((bfunction_t *) f)->func (pr);
|
||||
} else {
|
||||
PR_EnterFunction (pr, newf);
|
||||
PR_EnterFunction (pr, f);
|
||||
}
|
||||
st = pr->pr_statements + pr->pr_xstatement;
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue