From fd05d94789a5ad1536d0304f6655629efff83697 Mon Sep 17 00:00:00 2001 From: Karl Zylinski Date: Wed, 2 Oct 2024 17:47:04 +0200 Subject: [PATCH] Add make_map that just takes an allocator and no capacity, similar to make_dynamic_array. This renames the old make_map to make_map_cap. --- base/runtime/core_builtin.odin | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/base/runtime/core_builtin.odin b/base/runtime/core_builtin.odin index dbeff51d4..3dad2fdbc 100644 --- a/base/runtime/core_builtin.odin +++ b/base/runtime/core_builtin.odin @@ -383,12 +383,23 @@ _make_dynamic_array_len_cap :: proc(array: ^Raw_Dynamic_Array, size_of_elem, ali return } -// `make_map` allocates and initializes a map. Like `new`, the first argument is a type, not a value. +// `make_map` initializes a map with an allocator. Like `new`, the first argument is a type, not a value. // Unlike `new`, `make`'s return value is the same as the type of its argument, not a pointer to it. // // Note: Prefer using the procedure group `make`. @(builtin, require_results) -make_map :: proc($T: typeid/map[$K]$E, #any_int capacity: int = 1< (m: T, err: Allocator_Error) #optional_allocator_error { +make_map :: proc($T: typeid/map[$K]$E, allocator := context.allocator) -> (m: T) { + m.allocator = allocator + return m +} + +// `make_map_cap` initializes a map with an allocator and allocates space using `capacity`. +// Like `new`, the first argument is a type, not a value. +// Unlike `new`, `make`'s return value is the same as the type of its argument, not a pointer to it. +// +// Note: Prefer using the procedure group `make`. +@(builtin, require_results) +make_map_cap :: proc($T: typeid/map[$K]$E, #any_int capacity: int = 1< (m: T, err: Allocator_Error) #optional_allocator_error { make_map_expr_error_loc(loc, capacity) context.allocator = allocator @@ -425,6 +436,7 @@ make :: proc{ make_dynamic_array_len, make_dynamic_array_len_cap, make_map, + make_map_cap, make_multi_pointer, make_soa_slice,