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/map.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/map.cpp') diff --git a/src/map.cpp b/src/map.cpp index ae6bf9f74..85836fccb 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -89,8 +89,11 @@ template void multi_map_remove_all(Map *h, HashKey const &key); template gb_inline void map_init(Map *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 @@ -161,7 +164,7 @@ template void map_rehash(Map *h, isize new_count) { isize i, j; Map nh = {}; - map_init(&nh, h->hashes.allocator); + 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