From d09ac8943ac38b955e9a10d22e5c2f3fba8e7eaa Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 21 May 2020 16:27:40 +0100 Subject: Minor fixes to improve hash map/set performance --- src/string_map.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/string_map.cpp') diff --git a/src/string_map.cpp b/src/string_map.cpp index 485048154..7a446937a 100644 --- a/src/string_map.cpp +++ b/src/string_map.cpp @@ -7,7 +7,7 @@ struct StringMapFindResult { struct StringHashKey { u64 hash; - String string; + String string; }; StringHashKey string_hashing_proc(void const *data, isize len) { @@ -65,8 +65,11 @@ template void string_map_rehash (StringMap *h, isize n template gb_inline void string_map_init(StringMap *h, gbAllocator a, isize capacity) { - array_init(&h->hashes, a, 0, capacity); + array_init(&h->hashes, a, capacity); array_init(&h->entries, a, 0, capacity); + for (isize i = 0; i < capacity; i++) { + h->hashes.data[i] = -1; + } } template @@ -136,7 +139,7 @@ template void string_map_rehash(StringMap *h, isize new_count) { isize i, j; StringMap nh = {}; - string_map_init(&nh, h->hashes.allocator); + string_map_init(&nh, h->hashes.allocator, new_count); array_resize(&nh.hashes, new_count); array_reserve(&nh.entries, h->entries.count); for (i = 0; i < new_count; i++) { -- cgit v1.2.3