From bbb2164e38e3930cb79c5e7bc61b421e38131361 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 5 Jan 2023 01:25:37 +0000 Subject: Inline map gets; cast explicitly on TOMBSTONE checking --- src/string_map.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/string_map.cpp') diff --git a/src/string_map.cpp b/src/string_map.cpp index 74a16de73..facd00bb0 100644 --- a/src/string_map.cpp +++ b/src/string_map.cpp @@ -180,9 +180,18 @@ gb_internal void string_map_rehash(StringMap *h, isize new_count) { template gb_internal T *string_map_get(StringMap *h, StringHashKey const &key) { - isize index = string_map__find(h, key).entry_index; - if (index != MAP_SENTINEL) { - return &h->entries.data[index].value; + MapFindResult fr = {MAP_SENTINEL, MAP_SENTINEL, MAP_SENTINEL}; + if (h->hashes.count != 0) { + fr.hash_index = cast(MapIndex)(key.hash & (h->hashes.count-1)); + fr.entry_index = h->hashes.data[fr.hash_index]; + while (fr.entry_index != MAP_SENTINEL) { + auto *entry = &h->entries.data[fr.entry_index]; + if (string_hash_key_equal(entry->key, key)) { + return &entry->value; + } + fr.entry_prev = fr.entry_index; + fr.entry_index = entry->next; + } } return nullptr; } -- cgit v1.2.3