aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2022-09-17 13:11:29 +0100
committergingerBill <bill@gingerbill.org>2022-09-17 13:11:29 +0100
commitfbf036a654f54b4104f6252cac8fce6c9375daaf (patch)
tree7a0d58a08a199785f02ac97cbaac022763626f6c
parent40bcfc7c8df2e4e76a75f543c43f97cf9d050925 (diff)
Wrap `__dynamic_map_find` for certain cases
-rw-r--r--core/runtime/core_builtin.odin8
-rw-r--r--core/runtime/dynamic_map_internal.odin13
2 files changed, 12 insertions, 9 deletions
diff --git a/core/runtime/core_builtin.odin b/core/runtime/core_builtin.odin
index 92b3e9677..558a04bf9 100644
--- a/core/runtime/core_builtin.odin
+++ b/core/runtime/core_builtin.odin
@@ -325,8 +325,7 @@ delete_key :: proc(m: ^$T/map[$K]$V, key: K) -> (deleted_key: K, deleted_value:
if m != nil {
key := key
h := __get_map_header(m)
- hash := __get_map_hash(&key)
- fr := __dynamic_map_find(h, hash)
+ fr := __map_find(h, &key)
if fr.entry_index >= 0 {
entry := __dynamic_map_get_entry(h, fr.entry_index)
deleted_key = (^K)(uintptr(entry)+h.key_offset)^
@@ -674,9 +673,8 @@ shrink_dynamic_array :: proc(array: ^$T/[dynamic]$E, new_cap := -1, loc := #call
map_insert :: proc(m: ^$T/map[$K]$V, key: K, value: V, loc := #caller_location) -> (ptr: ^V) {
key, value := key, value
h := __get_map_header(m)
- hash := __get_map_hash(&key)
-
- data := uintptr(__dynamic_map_set(h, hash, &value, loc))
+
+ data := uintptr(__dynamic_map_set(h, __get_map_key_hash(&key), &key, &value, loc))
return (^V)(data + h.value_offset)
}
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 {