X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=code.c;h=e6cd6a313cd2f6812a69d1482423185894bd1a21;hp=1edaa47e88c9f2d4ba5ca4fa36270446170ff012;hb=35ba2dcaf99f4352869ad8519c35fefb1c53dd93;hpb=307746dc35b5757afc2108f44c5e9c3000e2a9e7 diff --git a/code.c b/code.c index 1edaa47..e6cd6a3 100644 --- a/code.c +++ b/code.c @@ -59,7 +59,8 @@ void code_init() { int i = 0; code_entfields = 0; - code_string_cache = util_htnew(1024); + + code_string_cache = util_htnew(OPTS_OPTIMIZATION(OPTIM_OVERLAP_STRINGS) ? 0x100 : 1024); /* * The way progs.dat is suppose to work is odd, there needs to be @@ -75,6 +76,7 @@ void code_init() { vec_push(code_fields, empty_def); } +void *code_util_str_htgeth(hash_table_t *ht, const char *key, size_t bin); uint32_t code_genstring(const char *str) { uint32_t off; @@ -92,8 +94,14 @@ uint32_t code_genstring(const char *str) return code_string_cached_empty; } - hash = util_hthash(code_string_cache, str); - existing = util_htgeth(code_string_cache, str, hash); + if (OPTS_OPTIMIZATION(OPTIM_OVERLAP_STRINGS)) { + hash = ((unsigned char*)str)[strlen(str)-1]; + existing = code_util_str_htgeth(code_string_cache, str, hash); + } else { + hash = util_hthash(code_string_cache, str); + existing = util_htgeth(code_string_cache, str, hash); + } + if (existing) return HASH_ENTRY_TO_QCINT(existing); @@ -101,7 +109,6 @@ uint32_t code_genstring(const char *str) vec_upload(code_chars, str, strlen(str)+1); util_htseth(code_string_cache, str, hash, QCINT_TO_HASH_ENTRY(off)); - existing = util_htgeth(code_string_cache, str, hash); return off; }