From 9933ca8b56cbabf32df295c266344b98801781b5 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 8 Apr 2024 23:58:30 +0100 Subject: [PATCH] Make `map_total_allocation_size` public; Add `map_total_allocation_size_from_value` --- base/runtime/dynamic_map_internal.odin | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/base/runtime/dynamic_map_internal.odin b/base/runtime/dynamic_map_internal.odin index 642a6fb18..5ad155400 100644 --- a/base/runtime/dynamic_map_internal.odin +++ b/base/runtime/dynamic_map_internal.odin @@ -333,7 +333,7 @@ map_kvh_data_values_dynamic :: proc "contextless" (m: Raw_Map, #no_alias info: ^ } -@(private, require_results) +@(require_results) map_total_allocation_size :: #force_inline proc "contextless" (capacity: uintptr, info: ^Map_Info) -> uintptr { round :: #force_inline proc "contextless" (value: uintptr) -> uintptr { CACHE_MASK :: MAP_CACHE_LINE_SIZE - 1 @@ -350,6 +350,12 @@ map_total_allocation_size :: #force_inline proc "contextless" (capacity: uintptr return size } +@(require_results) +map_total_allocation_size_from_value :: #force_inline proc "contextless" (m: $M/map[$K]$V) -> uintptr { + return map_total_allocation_size(uintptr(cap(m)), map_info(M)) +} + + // The only procedure which needs access to the context is the one which allocates the map. @(require_results) map_alloc_dynamic :: proc "odin" (info: ^Map_Info, log2_capacity: uintptr, allocator := context.allocator, loc := #caller_location) -> (result: Raw_Map, err: Allocator_Error) {