diff options
| author | gingerBill <bill@gingerbill.org> | 2022-09-17 13:11:29 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-09-17 13:11:29 +0100 |
| commit | fbf036a654f54b4104f6252cac8fce6c9375daaf (patch) | |
| tree | 7a0d58a08a199785f02ac97cbaac022763626f6c /core/runtime/dynamic_map_internal.odin | |
| parent | 40bcfc7c8df2e4e76a75f543c43f97cf9d050925 (diff) | |
Wrap `__dynamic_map_find` for certain cases
Diffstat (limited to 'core/runtime/dynamic_map_internal.odin')
| -rw-r--r-- | core/runtime/dynamic_map_internal.odin | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/core/runtime/dynamic_map_internal.odin b/core/runtime/dynamic_map_internal.odin index 7326d761d..be7f73339 100644 --- a/core/runtime/dynamic_map_internal.odin +++ b/core/runtime/dynamic_map_internal.odin @@ -11,11 +11,9 @@ Map_Hash :: struct { key_ptr: rawptr, // address of Map_Entry_Header.key } -__get_map_hash :: proc "contextless" (k: ^$K) -> (map_hash: Map_Hash) { +__get_map_key_hash :: proc "contextless" (k: ^$K) -> uintptr { hasher := intrinsics.type_hasher_proc(K) - map_hash.key_ptr = k - map_hash.hash = hasher(k, 0) - return + return hasher(k, 0) } __get_map_hash_from_entry :: proc "contextless" (h: Map_Header, entry: ^Map_Entry_Header, hash: ^Map_Hash) { @@ -347,6 +345,13 @@ __dynamic_map_hash_equal :: #force_inline proc "contextless" (h: Map_Header, a, return a.hash == b.hash && h.equal(a.key_ptr, b.key_ptr) } + +__map_find :: proc "contextless" (h: Map_Header, key_ptr: ^$K) -> Map_Find_Result #no_bounds_check { + hash := __get_map_key_hash(key_ptr) + return __dynamic_map_find(h, {hash, key_ptr}) +} + + __dynamic_map_find :: proc "contextless" (using h: Map_Header, hash: Map_Hash) -> Map_Find_Result #no_bounds_check { fr := Map_Find_Result{MAP_SENTINEL, MAP_SENTINEL, MAP_SENTINEL} if n := uintptr(len(m.hashes)); n != 0 { |