diff --git a/tools/qfcc/include/qfcc.h b/tools/qfcc/include/qfcc.h index 88e871fa5..72085aab5 100644 --- a/tools/qfcc/include/qfcc.h +++ b/tools/qfcc/include/qfcc.h @@ -454,5 +454,6 @@ extern int precache_files_block[MAX_SOUNDS]; extern int numfiles; int CopyString (char *str); +int ReuseString (char *str); diff --git a/tools/qfcc/source/pr_comp.c b/tools/qfcc/source/pr_comp.c index 5d7339b56..6e6a43652 100644 --- a/tools/qfcc/source/pr_comp.c +++ b/tools/qfcc/source/pr_comp.c @@ -714,7 +714,7 @@ PR_ParseDefs (void) else df->first_statement = f->code; - df->s_name = CopyString (f->def->name); + df->s_name = ReuseString (f->def->name); df->s_file = s_file; df->numparms = f->def->type->num_parms; df->locals = locals_end - locals_start; @@ -752,7 +752,7 @@ PR_CompileFile (char *string, char *filename) PR_ClearGrabMacros (); // clear the frame macros pr_file_p = string; - s_file = CopyString (filename); + s_file = ReuseString (filename); pr_source_line = 0; diff --git a/tools/qfcc/source/pr_def.c b/tools/qfcc/source/pr_def.c index d3366d0f7..4e76edaed 100644 --- a/tools/qfcc/source/pr_def.c +++ b/tools/qfcc/source/pr_def.c @@ -55,7 +55,7 @@ PR_GetDef (type_t *type, char *name, def_t *scope, qboolean allocate) char element[MAX_NAME]; if (!defs_by_name) { - defs_by_name = Hash_NewTable (1021, defs_get_key, 0, &defs_by_name); + defs_by_name = Hash_NewTable (16381, defs_get_key, 0, &defs_by_name); } // see if the name is already in use diff --git a/tools/qfcc/source/pr_imm.c b/tools/qfcc/source/pr_imm.c index 11c066b05..ded386987 100644 --- a/tools/qfcc/source/pr_imm.c +++ b/tools/qfcc/source/pr_imm.c @@ -67,9 +67,9 @@ PR_ParseImmediate (void) hashtab_t *tab = 0; if (!string_imm_defs) { - string_imm_defs = Hash_NewTable (1021, string_imm_get_key, 0, 0); - float_imm_defs = Hash_NewTable (1021, float_imm_get_key, 0, 0); - vector_imm_defs = Hash_NewTable (1021, vector_imm_get_key, 0, 0); + string_imm_defs = Hash_NewTable (16381, string_imm_get_key, 0, 0); + float_imm_defs = Hash_NewTable (16381, float_imm_get_key, 0, 0); + vector_imm_defs = Hash_NewTable (16381, vector_imm_get_key, 0, 0); } if (pr_immediate_type == &type_string) { cn = (def_t*) Hash_Find (string_imm_defs, pr_immediate_string); diff --git a/tools/qfcc/source/qfcc.c b/tools/qfcc/source/qfcc.c index e2dd39691..b03f5b835 100644 --- a/tools/qfcc/source/qfcc.c +++ b/tools/qfcc/source/qfcc.c @@ -31,6 +31,7 @@ # include "config.h" #endif #include +#include #include #include @@ -109,17 +110,42 @@ WriteFiles (void) Return an offset from the string heap */ +static hashtab_t *strings_tab; + +static char * +stings_get_key (void *_str, void *unsued) +{ + return (char*)_str; +} + int CopyString (char *str) { int old; + if (!strings_tab) { + strings_tab = Hash_NewTable (16381, stings_get_key, 0, 0); + } old = strofs; strcpy (strings + strofs, str); strofs += strlen (str) + 1; + Hash_Add (strings_tab, strings + old); return old; } +int +ReuseString (char *str) +{ + char *s; + + if (!strings_tab) + return CopyString (str); + s = Hash_Find (strings_tab, str); + if (s) + return s - strings; + return CopyString (str); +} + void PrintStrings (void) { @@ -215,7 +241,7 @@ WriteData (int crc) dd = &fields[numfielddefs]; numfielddefs++; dd->type = def->type->aux_type->type; - dd->s_name = CopyString (def->name); + dd->s_name = ReuseString (def->name); dd->ofs = G_INT (def->ofs); } @@ -227,7 +253,7 @@ WriteData (int crc) && def->type->type != ev_func && def->type->type != ev_field && def->scope == NULL) dd->type |= DEF_SAVEGLOBAL; - dd->s_name = CopyString (def->name); + dd->s_name = ReuseString (def->name); dd->ofs = def->ofs; }