Memoize the address of the '__line' symbol instead of searching for it in loctab/glbtab every new line

This commit is contained in:
Daniel_Cortez 2017-10-20 23:02:34 +07:00
parent a4dbe02330
commit aa9f589bf5
5 changed files with 6 additions and 12 deletions

View File

@ -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" */

View File

@ -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;

View File

@ -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);
}

View File

@ -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.

View File

@ -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" */