From f8c2629a3ecca518d2c5ca83cab0cd2c503d3e42 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 2 Jul 2010 18:15:59 -0700 Subject: [PATCH] Fixed O(n^2) generation of debug info tables (bug 4493, r=fyren). --- sourcepawn/compiler/sc.h | 1 + sourcepawn/compiler/sc6.c | 25 +++++++++++++++++-------- sourcepawn/compiler/sclist.c | 5 +++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/sourcepawn/compiler/sc.h b/sourcepawn/compiler/sc.h index c762b8c3c..b696e880a 100644 --- a/sourcepawn/compiler/sc.h +++ b/sourcepawn/compiler/sc.h @@ -724,6 +724,7 @@ SC_FUNC stringlist *insert_dbgline(int linenr); SC_FUNC stringlist *insert_dbgsymbol(symbol *sym); SC_FUNC char *get_dbgstring(int index); SC_FUNC void delete_dbgstringtable(void); +SC_FUNC stringlist *get_dbgstrings(); /* function prototypes in SCMEMFILE.C */ #if !defined tMEMFILE diff --git a/sourcepawn/compiler/sc6.c b/sourcepawn/compiler/sc6.c index c795c1764..c59524949 100644 --- a/sourcepawn/compiler/sc6.c +++ b/sourcepawn/compiler/sc6.c @@ -1064,13 +1064,15 @@ static void append_dbginfo(FILE *fout) AMX_DBG_LINE dbgline; AMX_DBG_SYMBOL dbgsym; AMX_DBG_SYMDIM dbgidxtag[sDIMEN_MAX]; - int index,dim,dbgsymdim; + int dim,dbgsymdim; char *str,*prevstr,*name,*prevname; ucell codeidx,previdx; constvalue *constptr; char symname[2*sNAMEMAX+16]; int16_t id1,id2; ucell address; + stringlist *dbgstrs = get_dbgstrings(); + stringlist *iter; /* header with general information */ memset(&dbghdr, 0, sizeof dbghdr); @@ -1079,13 +1081,16 @@ static void append_dbginfo(FILE *fout) dbghdr.file_version=CUR_FILE_VERSION; dbghdr.amx_version=MIN_AMX_VERSION; + dbgstrs=dbgstrs->next; + /* first pass: collect the number of items in various tables */ /* file table */ previdx=0; prevstr=NULL; prevname=NULL; - for (index=0; (str=get_dbgstring(index))!=NULL; index++) { + for (iter=dbgstrs; iter!=NULL; iter=iter->next) { + str = iter->line; assert(str!=NULL); assert(str[0]!='\0' && str[1]==':'); if (str[0]=='F') { @@ -1109,7 +1114,8 @@ static void append_dbginfo(FILE *fout) } /* if */ /* line number table */ - for (index=0; (str=get_dbgstring(index))!=NULL; index++) { + for (iter=dbgstrs; iter!=NULL; iter=iter->next) { + str = iter->line; assert(str!=NULL); assert(str[0]!='\0' && str[1]==':'); if (str[0]=='L') { @@ -1119,7 +1125,8 @@ static void append_dbginfo(FILE *fout) } /* for */ /* symbol table */ - for (index=0; (str=get_dbgstring(index))!=NULL; index++) { + for (iter=dbgstrs; iter!=NULL; iter=iter->next) { + str = iter->line; assert(str!=NULL); assert(str[0]!='\0' && str[1]==':'); if (str[0]=='S') { @@ -1173,8 +1180,8 @@ static void append_dbginfo(FILE *fout) previdx=0; prevstr=NULL; prevname=NULL; - for (index=0; (str=get_dbgstring(index))!=NULL; index++) { - assert(str!=NULL); + for (iter=dbgstrs; iter!=NULL; iter=iter->next) { + str = iter->line; assert(str[0]!='\0' && str[1]==':'); if (str[0]=='F') { codeidx=hex2long(str+2,&name); @@ -1203,7 +1210,8 @@ static void append_dbginfo(FILE *fout) } /* if */ /* line number table */ - for (index=0; (str=get_dbgstring(index))!=NULL; index++) { + for (iter=dbgstrs; iter!=NULL; iter=iter->next) { + str = iter->line; assert(str!=NULL); assert(str[0]!='\0' && str[1]==':'); if (str[0]=='L') { @@ -1218,7 +1226,8 @@ static void append_dbginfo(FILE *fout) } /* for */ /* symbol table */ - for (index=0; (str=get_dbgstring(index))!=NULL; index++) { + for (iter=dbgstrs; iter!=NULL; iter=iter->next) { + str = iter->line; assert(str!=NULL); assert(str[0]!='\0' && str[1]==':'); if (str[0]=='S') { diff --git a/sourcepawn/compiler/sclist.c b/sourcepawn/compiler/sclist.c index a2e83296a..88f4fd47f 100644 --- a/sourcepawn/compiler/sclist.c +++ b/sourcepawn/compiler/sclist.c @@ -519,6 +519,11 @@ SC_FUNC stringlist *insert_dbgsymbol(symbol *sym) return NULL; } +SC_FUNC stringlist *get_dbgstrings() +{ + return &dbgstrings; +} + SC_FUNC char *get_dbgstring(int index) { return get_string(&dbgstrings,index);