change pr_obj_msgSend and pr_obj_msgSend_super so they either call builtin

methods directly or setup the progs struct for a normal function call to
call a progs method rather than recursively calling PR_ExecuteProgram. This
will reduce method call overhead (both cpu and stack usage), fix the loss
of tracing when calling a method and makes it possible to break out of the
progs engine simply if threaded progs are ever implemented.
This commit is contained in:
Bill Currie 2002-10-15 18:53:33 +00:00
parent fcb06dbd84
commit 1f0b6e84a5
3 changed files with 24 additions and 2 deletions

View file

@ -65,6 +65,7 @@ void PR_Init (void);
void PR_Init_Cvars (void);
void PR_PrintStatement (progs_t * pr, dstatement_t *s);
int PR_EnterFunction (progs_t * pr, dfunction_t *f);
void PR_ExecuteProgram (progs_t *pr, func_t fnum);
void PR_LoadProgsFile (progs_t * pr, QFile *file, int size, int edicts,
int zone);

View file

@ -774,6 +774,7 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum)
|| !pr->builtins[i]->proc)
PR_RunError (pr, "Bad builtin call number");
pr->builtins[i]->proc (pr);
st = pr->pr_statements + pr->pr_xstatement;
break;
}

View file

@ -48,6 +48,25 @@ static const char rcsid[] =
#include "compat.h"
static void
call_function (progs_t *pr, func_t func)
{
dfunction_t *newf;
newf = pr->pr_functions + func;
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);
} else {
pr->pr_xstatement = PR_EnterFunction (pr, newf);
}
}
static const char *
class_get_key (void *c, void *pr)
{
@ -357,7 +376,8 @@ pr_obj_msgSend (progs_t *pr)
PR_RunError (pr, "%s does not respond to %s",
PR_GetString (pr, object_get_class_name (pr, self)),
PR_GetString (pr, _cmd->sel_id));
PR_ExecuteProgram (pr, imp);
call_function (pr, imp);
}
static void
@ -378,7 +398,7 @@ pr_obj_msgSend_super (progs_t *pr)
PR_RunError (pr, "%s does not respond to %s",
PR_GetString (pr, object_get_class_name (pr, self)),
PR_GetString (pr, _cmd->sel_id));
PR_ExecuteProgram (pr, imp);
call_function (pr, imp);
}
static void