diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2020-01-26 16:19:50 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-26 16:19:50 +0000 |
| commit | d658a8fca5299ce9263ab2158558eb4e125441c8 (patch) | |
| tree | 3dd1a43a67e032fa9797e37c2dd3bd50fb51ec0a | |
| parent | 14c4fed94ca0a401892409c6a4e8a018e65b0e4c (diff) | |
| parent | abe87898903853c5c57fc5e436025e19526e9b71 (diff) | |
Merge pull request #545 from Tetralux/patch-2
Fix `make(map[K]V, 0)` by ensuring `reserve` always sets an allocator
| -rw-r--r-- | core/runtime/core.odin | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/core/runtime/core.odin b/core/runtime/core.odin index ac623a53e..ad8b83fee 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -1125,12 +1125,14 @@ __dynamic_array_make :: proc(array_: rawptr, elem_size, elem_align: int, len, ca __dynamic_array_reserve :: proc(array_: rawptr, elem_size, elem_align: int, cap: int, loc := #caller_location) -> bool { array := (^Raw_Dynamic_Array)(array_); - if cap <= array.cap do return true; - + // NOTE(tetra, 2020-01-26): We set the allocator before earlying-out below, because user code is usually written + // assuming that appending/reserving will set the allocator, if it is not already set. if array.allocator.procedure == nil { array.allocator = context.allocator; } assert(array.allocator.procedure != nil); + + if cap <= array.cap do return true; old_size := array.cap * elem_size; new_size := cap * elem_size; |