mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Cleanup soa resize logic—reduce nesting
This commit is contained in:
@@ -249,14 +249,19 @@ _reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, capacity: int, zero_memory: boo
|
|||||||
|
|
||||||
old_data := (^rawptr)(array)^
|
old_data := (^rawptr)(array)^
|
||||||
|
|
||||||
if old_data != nil {
|
resize: if old_data != nil {
|
||||||
|
|
||||||
new_bytes, resize_err := array.allocator.procedure(
|
new_bytes, resize_err := array.allocator.procedure(
|
||||||
array.allocator.data, .Resize_Non_Zeroed, new_size, max_align,
|
array.allocator.data, .Resize_Non_Zeroed, new_size, max_align,
|
||||||
old_data, old_size, loc,
|
old_data, old_size, loc,
|
||||||
)
|
)
|
||||||
new_data := raw_data(new_bytes)
|
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
|
||||||
|
|
||||||
@@ -268,8 +273,8 @@ _reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, capacity: int, zero_memory: boo
|
|||||||
// to: |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
|
// move old data to the end of the new allocation to avoid overlap
|
||||||
old_start := uintptr(new_data) + uintptr(new_size - old_size)
|
old_data = rawptr(uintptr(new_data) + uintptr(new_size - old_size))
|
||||||
mem_copy(rawptr(old_start), new_data, old_size)
|
mem_copy(old_data, new_data, old_size)
|
||||||
|
|
||||||
// now: |_ _ _ x x y y z z|
|
// now: |_ _ _ x x y y z z|
|
||||||
|
|
||||||
@@ -280,7 +285,7 @@ _reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, capacity: int, zero_memory: boo
|
|||||||
new_offset = align_forward_int(new_offset, max_align)
|
new_offset = align_forward_int(new_offset, max_align)
|
||||||
|
|
||||||
new_data_elem := rawptr(uintptr(new_data) + uintptr(new_offset))
|
new_data_elem := rawptr(uintptr(new_data) + uintptr(new_offset))
|
||||||
old_data_elem := rawptr(old_start + uintptr(old_offset))
|
old_data_elem := rawptr(uintptr(old_data) + uintptr(old_offset))
|
||||||
|
|
||||||
old_size_elem := type.size * old_cap
|
old_size_elem := type.size * old_cap
|
||||||
new_size_elem := type.size * capacity
|
new_size_elem := type.size * capacity
|
||||||
@@ -300,11 +305,6 @@ _reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, capacity: int, zero_memory: boo
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if resize_err != .Mode_Not_Implemented {
|
|
||||||
return resize_err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
new_bytes := array.allocator.procedure(
|
new_bytes := array.allocator.procedure(
|
||||||
array.allocator.data, .Alloc if zero_memory else .Alloc_Non_Zeroed, new_size, max_align,
|
array.allocator.data, .Alloc if zero_memory else .Alloc_Non_Zeroed, new_size, max_align,
|
||||||
nil, old_size, loc,
|
nil, old_size, loc,
|
||||||
|
|||||||
Reference in New Issue
Block a user