diff options
| author | gingerBill <bill@gingerbill.org> | 2023-01-05 01:25:37 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2023-01-05 01:25:37 +0000 |
| commit | bbb2164e38e3930cb79c5e7bc61b421e38131361 (patch) | |
| tree | 5abcf64a674ed5e0d553fb8e621d0493088e7e93 /src/string_map.cpp | |
| parent | be23d83fc8a940de98d372276d475372e61b4bf2 (diff) | |
Inline map gets; cast explicitly on TOMBSTONE checking
Diffstat (limited to 'src/string_map.cpp')
| -rw-r--r-- | src/string_map.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
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<T> *h, isize new_count) { template <typename T> gb_internal T *string_map_get(StringMap<T> *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; } |