Fixed O(n) insertion of debug strings (bug 4495, r=fyren).

This commit is contained in:
David Anderson 2010-07-02 18:16:15 -07:00
parent f8c2629a3e
commit 7bc019547f
2 changed files with 17 additions and 12 deletions

View File

@ -269,7 +269,10 @@ enum {
typedef struct s_stringlist { typedef struct s_stringlist {
struct s_stringlist *next; struct s_stringlist *next;
char *line; union {
char *line;
struct s_stringlist *tail;
};
} stringlist; } stringlist;
typedef struct s_stringpair { typedef struct s_stringpair {

View File

@ -146,12 +146,12 @@ static stringlist *insert_string(stringlist *root,char *string)
error(103); /* insufficient memory (fatal error) */ error(103); /* insufficient memory (fatal error) */
if ((cur->line=duplicatestring(string))==NULL) if ((cur->line=duplicatestring(string))==NULL)
error(103); /* insufficient memory (fatal error) */ error(103); /* insufficient memory (fatal error) */
/* insert as "last" */ cur->next=NULL;
assert(root!=NULL); if (root->tail)
while (root->next!=NULL) root->tail->next=cur;
root=root->next; else
cur->next=root->next; root->next=cur;
root->next=cur; root->tail=cur;
return cur; return cur;
} }
@ -179,6 +179,8 @@ static int delete_string(stringlist *root,int index)
/* nothing */; /* nothing */;
if (cur->next!=NULL) { if (cur->next!=NULL) {
item=cur->next; item=cur->next;
if (root->tail == cur->next)
root->tail = cur;
cur->next=item->next; /* unlink from list */ cur->next=item->next; /* unlink from list */
assert(item->line!=NULL); assert(item->line!=NULL);
free(item->line); free(item->line);
@ -237,7 +239,7 @@ SC_FUNC void delete_aliastable(void)
} }
/* ----- include paths list -------------------------------------- */ /* ----- include paths list -------------------------------------- */
static stringlist includepaths = {NULL, NULL}; /* directory list for include files */ static stringlist includepaths; /* directory list for include files */
SC_FUNC stringlist *insert_path(char *path) SC_FUNC stringlist *insert_path(char *path)
{ {
@ -366,7 +368,7 @@ SC_FUNC void delete_substtable(void)
/* ----- input file list ----------------------------------------- */ /* ----- input file list ----------------------------------------- */
static stringlist sourcefiles = {NULL, NULL}; static stringlist sourcefiles;
SC_FUNC stringlist *insert_sourcefile(char *string) SC_FUNC stringlist *insert_sourcefile(char *string)
{ {
@ -387,7 +389,7 @@ SC_FUNC void delete_sourcefiletable(void)
/* ----- documentation tags -------------------------------------- */ /* ----- documentation tags -------------------------------------- */
#if !defined SC_LIGHT #if !defined SC_LIGHT
static stringlist docstrings = {NULL, NULL}; static stringlist docstrings;
SC_FUNC stringlist *insert_docstring(char *string) SC_FUNC stringlist *insert_docstring(char *string)
{ {
@ -413,7 +415,7 @@ SC_FUNC void delete_docstringtable(void)
/* ----- autolisting --------------------------------------------- */ /* ----- autolisting --------------------------------------------- */
static stringlist autolist = {NULL, NULL}; static stringlist autolist;
SC_FUNC stringlist *insert_autolist(char *string) SC_FUNC stringlist *insert_autolist(char *string)
{ {
@ -459,7 +461,7 @@ SC_FUNC void delete_autolisttable(void)
#define PRIxC "x" #define PRIxC "x"
#endif #endif
static stringlist dbgstrings = {NULL, NULL}; static stringlist dbgstrings;
SC_FUNC stringlist *insert_dbgfile(const char *filename) SC_FUNC stringlist *insert_dbgfile(const char *filename)
{ {