Fix assign_at_elems to match the same logic as assign_at_elem_string

This commit is contained in:
gingerBill
2023-12-18 22:22:08 +00:00
parent beb4699b46
commit 829e4cc67e
+7 -2
View File
@@ -234,6 +234,8 @@ delete :: proc{
delete_dynamic_array,
delete_slice,
delete_map,
delete_soa_slice,
delete_soa_dynamic_array,
}
@@ -587,11 +589,14 @@ assign_at_elem :: proc(array: ^$T/[dynamic]$E, index: int, arg: E, loc := #calle
@builtin
assign_at_elems :: proc(array: ^$T/[dynamic]$E, index: int, args: ..E, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #no_bounds_check #optional_allocator_error {
if index+len(args) < len(array) {
new_size := index + len(arg)
if len(args) == 0 {
ok = true
} else if new_size < len(array) {
copy(array[index:], args)
ok = true
} else {
resize(array, index+1+len(args), loc) or_return
resize(array, new_size, loc) or_return
copy(array[index:], args)
ok = true
}