From aa9f589bf52bb8d6741cdde745f54ffbf2ea3951 Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Fri, 20 Oct 2017 23:02:34 +0700 Subject: [PATCH] Memoize the address of the '__line' symbol instead of searching for it in loctab/glbtab every new line --- source/compiler/sc.h | 2 +- source/compiler/sc1.c | 3 ++- source/compiler/sc2.c | 3 ++- source/compiler/sc4.c | 9 --------- source/compiler/scvars.c | 1 + 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/source/compiler/sc.h b/source/compiler/sc.h index 72fe01d..84d33cf 100644 --- a/source/compiler/sc.h +++ b/source/compiler/sc.h @@ -617,7 +617,6 @@ SC_FUNC void setline(int chkbounds); SC_FUNC void setfiledirect(char *name); SC_FUNC void setfileconst(char *name); SC_FUNC void setlinedirect(int line); -SC_FUNC void setlineconst(int line); SC_FUNC void setlabel(int index); SC_FUNC void markexpr(optmark type,const char *name,cell offset); SC_FUNC void startfunc(char *fname); @@ -794,6 +793,7 @@ SC_FUNC int state_conflict_id(int listid1,int listid2); SC_VDECL symbol loctab; /* local symbol table */ SC_VDECL symbol glbtab; /* global symbol table */ SC_VDECL struct hashmap symbol_cache_map; +SC_VDECL symbol *line_sym; SC_VDECL cell *litq; /* the literal queue */ SC_VDECL unsigned char pline[]; /* the line read from the input file */ SC_VDECL const unsigned char *lptr;/* points to the current position in "pline" */ diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index a63de8e..80a3234 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -761,6 +761,7 @@ cleanup: delete_symbols(&loctab,0,TRUE,TRUE); /* delete local variables if not yet * done (i.e. on a fatal error) */ delete_symbols(&glbtab,0,TRUE,TRUE); + line_sym=NULL; hashmap_destroy(&symbol_cache_map); delete_consttable(&tagname_tab); delete_consttable(&libname_tab); @@ -1512,7 +1513,7 @@ static void setconstants(void) add_builtin_constant("__Pawn",VERSION_INT,sGLOBAL,0); add_builtin_constant("__PawnBuild",VERSION_BUILD,sGLOBAL,0); - add_builtin_constant("__line",0,sGLOBAL,0); + line_sym=add_builtin_constant("__line",0,sGLOBAL,0); add_builtin_constant("__compat",pc_compat,sGLOBAL,0); debug=0; diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index 9f4f0b4..233a40a 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -431,7 +431,8 @@ static void readline(unsigned char *line) line+=strlen((char*)line); } /* if */ fline+=1; - setlineconst(fline); + assert(line_sym!=NULL); + line_sym->addr=fline; } while (num>=0 && cont); } diff --git a/source/compiler/sc4.c b/source/compiler/sc4.c index 4124883..df22516 100644 --- a/source/compiler/sc4.c +++ b/source/compiler/sc4.c @@ -287,15 +287,6 @@ SC_FUNC void setlinedirect(int line) } /* if */ } -SC_FUNC void setlineconst(int line) -{ - symbol *sym; - - sym=findconst("__line",NULL); - assert(sym!=NULL); - sym->addr=fline; -} - /* setlabel * * Post a code label (specified as a number), on a new line. diff --git a/source/compiler/scvars.c b/source/compiler/scvars.c index a96df7c..1ca6054 100644 --- a/source/compiler/scvars.c +++ b/source/compiler/scvars.c @@ -34,6 +34,7 @@ SC_VDEFINE symbol loctab; /* local symbol table */ SC_VDEFINE symbol glbtab; /* global symbol table */ SC_VDEFINE struct hashmap symbol_cache_map; +SC_VDEFINE symbol *line_sym=NULL; SC_VDEFINE cell *litq; /* the literal queue */ SC_VDEFINE unsigned char pline[sLINEMAX+1]; /* the line read from the input file */ SC_VDEFINE const unsigned char *lptr; /* points to the current position in "pline" */