diff options
| author | gingerBill <bill@gingerbill.org> | 2022-09-21 13:03:13 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-09-21 13:03:13 +0100 |
| commit | ff97a731521dbeb9a6457a889f30f4fa69e080f7 (patch) | |
| tree | 984fa5a3fe7cc9cec973689f2553f0634b37920e /core/runtime | |
| parent | 769d8dd038601d6e7ad0ddb445593e65c4596074 (diff) | |
Reduce unnecessary map gets
Diffstat (limited to 'core/runtime')
| -rw-r--r-- | core/runtime/core_builtin.odin | 3 | ||||
| -rw-r--r-- | core/runtime/dynamic_map_internal.odin | 28 |
2 files changed, 21 insertions, 10 deletions
diff --git a/core/runtime/core_builtin.odin b/core/runtime/core_builtin.odin index f8e39b8b2..568deed3b 100644 --- a/core/runtime/core_builtin.odin +++ b/core/runtime/core_builtin.odin @@ -296,7 +296,8 @@ clear_map :: proc "contextless" (m: ^$T/map[$K]$V) { @builtin reserve_map :: proc(m: ^$T/map[$K]$V, capacity: int, loc := #caller_location) { if m != nil { - __dynamic_map_reserve(__get_map_header(m), uint(capacity), loc) + h := __get_map_header_table(T) + __dynamic_map_reserve(m, h, uint(capacity), loc) } } diff --git a/core/runtime/dynamic_map_internal.odin b/core/runtime/dynamic_map_internal.odin index 5a683f234..011513162 100644 --- a/core/runtime/dynamic_map_internal.odin +++ b/core/runtime/dynamic_map_internal.odin @@ -57,17 +57,20 @@ Map_Header :: struct { } // USED INTERNALLY BY THE COMPILER -__dynamic_map_get :: proc "contextless" (h: Map_Header, key_hash: uintptr, key_ptr: rawptr) -> rawptr { - index := __dynamic_map_find(h, key_hash, key_ptr).entry_index - if index != MAP_SENTINEL { - data := uintptr(__dynamic_map_get_entry(h, index)) - return rawptr(data + h.value_offset) +__dynamic_map_get :: proc "contextless" (m: rawptr, table: Map_Header_Table, key_hash: uintptr, key_ptr: rawptr) -> rawptr { + if m != nil { + h := Map_Header{(^Raw_Map)(m), table} + index := __dynamic_map_find(h, key_hash, key_ptr).entry_index + if index != MAP_SENTINEL { + data := uintptr(__dynamic_map_get_entry(h, index)) + return rawptr(data + h.value_offset) + } } return nil } // USED INTERNALLY BY THE COMPILER -__dynamic_map_set :: proc "odin" (h: Map_Header, key_hash: uintptr, key_ptr: rawptr, value: rawptr, loc := #caller_location) -> ^Map_Entry_Header #no_bounds_check { +__dynamic_map_set :: proc "odin" (m: rawptr, table: Map_Header_Table, key_hash: uintptr, key_ptr: rawptr, value: rawptr, loc := #caller_location) -> ^Map_Entry_Header #no_bounds_check { add_entry :: proc "odin" (h: Map_Header, key_hash: uintptr, key_ptr: rawptr, loc := #caller_location) -> Map_Index { prev := Map_Index(h.m.entries.len) c := Map_Index(__dynamic_array_append_nothing(&h.m.entries, h.entry_size, h.entry_align, loc)) @@ -79,11 +82,14 @@ __dynamic_map_set :: proc "odin" (h: Map_Header, key_hash: uintptr, key_ptr: raw } return prev } + assert(condition = m != nil) + + h := Map_Header{(^Raw_Map)(m), table} index := MAP_SENTINEL if len(h.m.hashes) == 0 { - __dynamic_map_reserve(h, INITIAL_MAP_CAP, loc) + __dynamic_map_reserve(m, table, INITIAL_MAP_CAP, loc) __dynamic_map_grow(h, loc) } @@ -119,7 +125,11 @@ __dynamic_map_set :: proc "odin" (h: Map_Header, key_hash: uintptr, key_ptr: raw } // USED INTERNALLY BY THE COMPILER -__dynamic_map_reserve :: proc "odin" (h: Map_Header, cap: uint, loc := #caller_location) { +__dynamic_map_reserve :: proc "odin" (m: rawptr, table: Map_Header_Table, cap: uint, loc := #caller_location) { + assert(condition = m != nil) + + h := Map_Header{(^Raw_Map)(m), table} + c := context if h.m.entries.allocator.procedure != nil { c.allocator = h.m.entries.allocator @@ -352,7 +362,7 @@ ceil_to_pow2 :: proc "contextless" (n: uint) -> uint { __dynamic_map_grow :: proc "odin" (h: Map_Header, loc := #caller_location) { new_count := max(uint(h.m.entries.cap) * 2, INITIAL_MAP_CAP) // Rehash through Reserve - __dynamic_map_reserve(h, new_count, loc) + __dynamic_map_reserve(h.m, h.table, new_count, loc) } __dynamic_map_full :: #force_inline proc "contextless" (h: Map_Header) -> bool { |