diff --git a/base/runtime/core_builtin_soa.odin b/base/runtime/core_builtin_soa.odin index ff27a4559..5baeb9e24 100644 --- a/base/runtime/core_builtin_soa.odin +++ b/base/runtime/core_builtin_soa.odin @@ -249,17 +249,63 @@ _reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, capacity: int, zero_memory: boo old_data := (^rawptr)(array)^ - new_bytes := array.allocator.procedure( - array.allocator.data, .Alloc if zero_memory else .Alloc_Non_Zeroed, new_size, max_align, - nil, old_size, loc, - ) or_return + new_bytes, resize_err := array.allocator.procedure( + array.allocator.data, .Resize if zero_memory else .Resize_Non_Zeroed, new_size, max_align, + old_data, old_size, loc, + ) new_data := raw_data(new_bytes) - - footer.cap = capacity - old_offset := 0 new_offset := 0 + + if resize_err == .None { + + footer.cap = capacity + + // Adjust layout + // before: |x x y y z z| + // now: |x x y y z z _ _ _| + // after: |x x _ y y _ z z _| + + for i in 0..