diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-10-08 20:54:05 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-10-08 20:54:05 -0700 |
commit | 31aec9f2132701f741d8786950190980a792fd96 (patch) | |
tree | b331db0c1b757ae21ecd237d5245d465a40e8c89 | |
parent | 758a8d52fb20d976d7fc459aa6ca34242a6ec0ee (diff) | |
download | txr-31aec9f2132701f741d8786950190980a792fd96.tar.gz txr-31aec9f2132701f741d8786950190980a792fd96.tar.bz2 txr-31aec9f2132701f741d8786950190980a792fd96.zip |
strings: revert caching of hash value.
Research indicates that this is something useful in
languages that abuse strings for implementing symbols.
We have interned symbols.
* lib.h (struct string): Remove hash member.
* lib.c (string_own, string, string_utf8, mkustring,
string_extend, replace_str, chr_str_set): Remove
all initializations and updates of the removed
hash member.
* hash.c (equal_hash): Do not cache string hash value.
-rw-r--r-- | hash.c | 7 | ||||
-rw-r--r-- | lib.c | 27 | ||||
-rw-r--r-- | lib.h | 4 |
3 files changed, 4 insertions, 34 deletions
@@ -315,13 +315,6 @@ ucnum equal_hash(val obj, int *count, ucnum seed) return equal_hash(obj->c.car, count, seed) + equal_hash(obj->c.cdr, count, seed + (CONS << 8)); case STR: -#if HAVE_MALLOC_USABLE_SIZE - if (seed == 0) { - return if3(obj->st.hash != 0, - obj->st.hash, - obj->st.hash = hash_c_str(obj->st.str, 0, count)); - } -#endif return hash_c_str(obj->st.str, seed, count); case CHR: return c_ch(obj); @@ -4859,9 +4859,7 @@ val string_own(wchar_t *str) obj->st.type = STR; obj->st.str = str; obj->st.len = nil; -#if HAVE_MALLOC_USABLE_SIZE - obj->st.hash = 0; -#else +#if !HAVE_MALLOC_USABLE_SIZE obj->st.alloc = 0; #endif return obj; @@ -4873,9 +4871,7 @@ val string(const wchar_t *str) obj->st.type = STR; obj->st.str = chk_strdup(str); obj->st.len = nil; -#if HAVE_MALLOC_USABLE_SIZE - obj->st.hash = 0; -#else +#if !HAVE_MALLOC_USABLE_SIZE obj->st.alloc = 0; #endif return obj; @@ -4887,9 +4883,7 @@ val string_utf8(const char *str) obj->st.type = STR; obj->st.str = utf8_dup_from(str); obj->st.len = nil; -#if HAVE_MALLOC_USABLE_SIZE - obj->st.hash = 0; -#else +#if !HAVE_MALLOC_USABLE_SIZE obj->st.alloc = 0; #endif return obj; @@ -4953,9 +4947,6 @@ val mkustring(val len) val init_str(val str, const wchar_t *data, val self) { wmemcpy(str->st.str, data, c_num(str->st.len, self)); -#if HAVE_MALLOC_USABLE_SIZE - str->st.hash = 0; -#endif return str; } @@ -5083,9 +5074,6 @@ val string_extend(val str, val tail, val finish_in) str->st.str[len] = c_chr(tail); str->st.str[len + 1] = 0; } -#if HAVE_MALLOC_USABLE_SIZE - str->st.hash = 0; -#endif } return str; @@ -5596,11 +5584,6 @@ val replace_str(val str_in, val items, val from, val to) from = max2(zero, min2(from, len)); to = max2(zero, min2(to, len)); - -#if HAVE_MALLOC_USABLE_SIZE - str_in->st.hash = 0; -#endif - { val len_rep = minus(to, from); val len_it = length(items); @@ -6885,10 +6868,6 @@ val chr_str_set(val str, val ind, val chr) self, str, nao); } -#if HAVE_MALLOC_USABLE_SIZE - str->st.hash = 0; -#endif - if (index < 0) { ind = plus(length_str(str), ind); index = c_num(ind, self); @@ -154,9 +154,7 @@ struct string { obj_common; wchar_t *str; val len; -#if HAVE_MALLOC_USABLE_SIZE - ucnum hash; -#else +#if !HAVE_MALLOC_USABLE_SIZE cnum alloc; #endif }; |