aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamian Tarnawski <gthetarnav@gmail.com>2025-08-24 15:17:13 +0200
committerDamian Tarnawski <gthetarnav@gmail.com>2025-08-24 15:17:13 +0200
commit95cfad67b776c4d839aa494fa88832a67c0c28cc (patch)
tree03a5c1d2dd3a6f53c521f484e1b840e2ed28e35e
parent8a894c6ce6cbedc187563a07a2bb689d9f8cdf56 (diff)
Cleanup soa resize logic—reduce nesting
-rw-r--r--base/runtime/core_builtin_soa.odin64
1 files 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 {
-
- footer.cap = capacity
+ #partial switch resize_err {
+ case .Mode_Not_Implemented: break resize
+ case .None: // continue resizing
+ case: return resize_err
+ }
- old_offset := 0
- new_offset := 0
+ footer.cap = capacity
- // Correct data memory
- // from: |x x y y z z _ _ _|
- // to: |x x _ y y _ z z _|
+ old_offset := 0
+ new_offset := 0
- // 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)
+ // Correct data memory
+ // from: |x x y y z z _ _ _|
+ // to: |x x _ y y _ z z _|
- // now: |_ _ _ x x y y z z|
+ // 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)
- for i in 0..<field_count {
- type := si.types[i].variant.(Type_Info_Multi_Pointer).elem
+ // now: |_ _ _ x x y y z z|
- old_offset = align_forward_int(old_offset, max_align)
- new_offset = align_forward_int(new_offset, max_align)
+ for i in 0..<field_count {
+ type := si.types[i].variant.(Type_Info_Multi_Pointer).elem
- new_data_elem := rawptr(uintptr(new_data) + uintptr(new_offset))
- old_data_elem := rawptr(old_start + uintptr(old_offset))
+ old_offset = align_forward_int(old_offset, max_align)
+ new_offset = align_forward_int(new_offset, max_align)
- old_size_elem := type.size * old_cap
- new_size_elem := type.size * capacity
+ new_data_elem := rawptr(uintptr(new_data) + uintptr(new_offset))
+ old_data_elem := rawptr(uintptr(old_data) + uintptr(old_offset))
- mem_copy(new_data_elem, old_data_elem, old_size_elem)
+ old_size_elem := type.size * old_cap
+ new_size_elem := type.size * capacity
- (^rawptr)(uintptr(array) + i*size_of(rawptr))^ = new_data_elem
+ mem_copy(new_data_elem, old_data_elem, old_size_elem)
- if zero_memory {
- mem_zero(rawptr(uintptr(new_data_elem) + uintptr(old_size_elem)), new_size_elem - old_size_elem)
- }
+ (^rawptr)(uintptr(array) + i*size_of(rawptr))^ = new_data_elem
- old_offset += old_size_elem
- new_offset += new_size_elem
+ if zero_memory {
+ mem_zero(rawptr(uintptr(new_data_elem) + uintptr(old_size_elem)), new_size_elem - old_size_elem)
}
- return nil
+ old_offset += old_size_elem
+ new_offset += new_size_elem
}
- if resize_err != .Mode_Not_Implemented {
- return resize_err
- }
+ return nil
}
new_bytes := array.allocator.procedure(