diff options
| author | Tetralux <tetraluxonpc@gmail.com> | 2024-11-16 05:49:25 +0000 |
|---|---|---|
| committer | Tetralux <tetraluxonpc@gmail.com> | 2024-11-16 06:13:12 +0000 |
| commit | 2f85257bad7a4089ae20564f29e2bb629c03b656 (patch) | |
| tree | 8e0007804bb763a2d58fb91cf358d8c0660a7529 /tests | |
| parent | 0781871efdcfeda13d3d8d51df62b5e578da774a (diff) | |
[runtime] `make(map[K]V)` should not allocate any capacity
`make(map[K]V)` was resolving to `make_map_cap()` which allocates initial capacity when it wasn't intended to.
It now calls `make_map()` which doesn't allocate any capacity.
Both `make(map[K]V)` and `make(map[K]V, allocator)` will NOT allocate initial capacity now.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/core/runtime/test_core_runtime.odin | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/core/runtime/test_core_runtime.odin b/tests/core/runtime/test_core_runtime.odin index f39caff48..84fd044cf 100644 --- a/tests/core/runtime/test_core_runtime.odin +++ b/tests/core/runtime/test_core_runtime.odin @@ -39,4 +39,28 @@ test_temp_allocator_returns_correct_size :: proc(t: ^testing.T) { bytes, err := mem.alloc_bytes(10, 16) testing.expect(t, err == nil) testing.expect(t, len(bytes) == 10) +} + +@(test) +test_init_cap_map_dynarray :: proc(t: ^testing.T) { + m1 := make(map[int]string) + defer delete(m1) + testing.expect(t, cap(m1) == 0) + testing.expect(t, m1.allocator.procedure == context.allocator.procedure) + + ally := context.temp_allocator + m2 := make(map[int]string, ally) + defer delete(m2) + testing.expect(t, cap(m2) == 0) + testing.expect(t, m2.allocator.procedure == ally.procedure) + + d1 := make([dynamic]string) + defer delete(d1) + testing.expect(t, cap(d1) == 0) + testing.expect(t, d1.allocator.procedure == context.allocator.procedure) + + d2 := make([dynamic]string, ally) + defer delete(d2) + testing.expect(t, cap(d2) == 0) + testing.expect(t, d2.allocator.procedure == ally.procedure) }
\ No newline at end of file |