aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2024-10-04 12:26:32 +0100
committerGitHub <noreply@github.com>2024-10-04 12:26:32 +0100
commitabbbfd2925ce69d2a90d35282a14070e79793944 (patch)
tree22c4355f0f10a6b4a7abe2d25f9756242548e940
parent9fe8095a848f1a8d81e4ac4b85cd666909c4eb7b (diff)
parentfd05d94789a5ad1536d0304f6655629efff83697 (diff)
Merge pull request #4340 from karl-zylinski/make-map
Add make_map that just sets the allocator without allocating anything
-rw-r--r--base/runtime/core_builtin.odin16
1 files 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<<MAP_MIN_LOG2_CAPACITY, allocator := context.allocator, loc := #caller_location) -> (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<<MAP_MIN_LOG2_CAPACITY, allocator := context.allocator, loc := #caller_location) -> (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,