From 95cfad67b776c4d839aa494fa88832a67c0c28cc Mon Sep 17 00:00:00 2001 From: Damian Tarnawski Date: Sun, 24 Aug 2025 15:17:13 +0200 Subject: [PATCH] =?UTF-8?q?Cleanup=20soa=20resize=20logic=E2=80=94reduce?= =?UTF-8?q?=20nesting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/runtime/core_builtin_soa.odin | 64 +++++++++++++++--------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/base/runtime/core_builtin_soa.odin b/base/runtime/core_builtin_soa.odin index d436b9a3a..9d042267a 100644 --- a/base/runtime/core_builtin_soa.odin +++ b/base/runtime/core_builtin_soa.odin @@ -249,60 +249,60 @@ _reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, capacity: int, zero_memory: boo old_data := (^rawptr)(array)^ - if old_data != nil { + resize: if old_data != nil { + new_bytes, resize_err := array.allocator.procedure( array.allocator.data, .Resize_Non_Zeroed, new_size, max_align, old_data, old_size, loc, ) new_data := raw_data(new_bytes) - if resize_err == .None { + #partial switch resize_err { + case .Mode_Not_Implemented: break resize + case .None: // continue resizing + case: return resize_err + } - footer.cap = capacity + footer.cap = capacity - old_offset := 0 - new_offset := 0 + old_offset := 0 + new_offset := 0 - // Correct data memory - // from: |x x y y z z _ _ _| - // to: |x x _ y y _ z z _| + // Correct data memory + // from: |x x y y z z _ _ _| + // to: |x x _ y y _ z z _| - // move old data to the end of the new allocation to avoid overlap - old_start := uintptr(new_data) + uintptr(new_size - old_size) - mem_copy(rawptr(old_start), new_data, old_size) + // move old data to the end of the new allocation to avoid overlap + old_data = rawptr(uintptr(new_data) + uintptr(new_size - old_size)) + mem_copy(old_data, new_data, old_size) - // now: |_ _ _ x x y y z z| + // now: |_ _ _ x x y y z z| - for i in 0..