aboutsummaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorfleandro <3987005+flga@users.noreply.github.com>2025-01-03 16:50:05 +0000
committerfleandro <3987005+flga@users.noreply.github.com>2025-01-03 16:50:05 +0000
commitc93e096d8f39cc97739e15a32f48ecfe83829593 (patch)
treebfaf3b00c93fd8b6fd6ba372c10d980e8f220083 /base
parent555bca2cb4adf964c97b333646c432cd8fa9392a (diff)
fix N=1 and cleanup tests
Diffstat (limited to 'base')
-rw-r--r--base/runtime/dynamic_map_internal.odin12
1 files changed, 6 insertions, 6 deletions
diff --git a/base/runtime/dynamic_map_internal.odin b/base/runtime/dynamic_map_internal.odin
index 281d4b88e..4e22aa25c 100644
--- a/base/runtime/dynamic_map_internal.odin
+++ b/base/runtime/dynamic_map_internal.odin
@@ -158,6 +158,11 @@ map_cell_index_static :: #force_inline proc "contextless" (cells: [^]Map_Cell($T
} else when (N & (N - 1)) == 0 && N <= 8*size_of(uintptr) {
// Likely case, N is a power of two because T is a power of two.
+ // Unique case, no need to index data here since only one element.
+ when N == 1 {
+ return &cells[index].data[0]
+ }
+
// Compute the integer log 2 of N, this is the shift amount to index the
// correct cell. Odin's intrinsics.count_leading_zeros does not produce a
// constant, hence this approach. We only need to check up to N = 64.
@@ -167,12 +172,7 @@ map_cell_index_static :: #force_inline proc "contextless" (cells: [^]Map_Cell($T
4 when N == 16 else
5 when N == 32 else 6
#assert(SHIFT <= MAP_CACHE_LINE_LOG2)
- // Unique case, no need to index data here since only one element.
- when N == 1 {
- return &cells[index >> SHIFT].data[0]
- } else {
- return &cells[index >> SHIFT].data[index & (N - 1)]
- }
+ return &cells[index >> SHIFT].data[index & (N - 1)]
} else {
// Least likely (and worst case), we pay for a division operation but we
// assume the compiler does not actually generate a division. N will be in the