mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-26 22:31:05 +00:00
no more redundant strings. costs ~7ms, though, but HALVING the strofs size
in frikbot seems worth it.
This commit is contained in:
parent
59e55834ed
commit
02b09f4e5c
5 changed files with 35 additions and 8 deletions
|
@ -454,5 +454,6 @@ extern int precache_files_block[MAX_SOUNDS];
|
|||
extern int numfiles;
|
||||
|
||||
int CopyString (char *str);
|
||||
int ReuseString (char *str);
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
# include "config.h"
|
||||
#endif
|
||||
#include <QF/crc.h>
|
||||
#include <QF/hash.h>
|
||||
#include <QF/qendian.h>
|
||||
#include <QF/sys.h>
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue