diff --git a/base/runtime/core_builtin.odin b/base/runtime/core_builtin.odin index 0a59167b2..7fa9ab4c8 100644 --- a/base/runtime/core_builtin.odin +++ b/base/runtime/core_builtin.odin @@ -1404,8 +1404,8 @@ resize_fixed_capacity_dynamic_array :: proc "contextless" (array: ^$T/[dynamic; if raw.len < length { size_of_elem :: size_of(E) - num_reused := min(N, length) - a.len - intrinsics.mem_zero(([^]byte)(a.data)[a.len*size_of_elem:], num_reused*size_of_elem) + num_reused := min(N, length) - raw.len + intrinsics.mem_zero(([^]byte)(a.data)[raw.len*size_of_elem:], num_reused*size_of_elem) } new_length := clamp(length, 0, N) raw.len = new_length diff --git a/tests/core/container/test_fixed_capacity_dynamic_array.odin b/tests/core/container/test_fixed_capacity_dynamic_array.odin index 91639fec6..bca4e20f3 100644 --- a/tests/core/container/test_fixed_capacity_dynamic_array.odin +++ b/tests/core/container/test_fixed_capacity_dynamic_array.odin @@ -26,11 +26,11 @@ test_fixed_capacity_dynamic_array_inject_at :: proc(t: ^testing.T) { array: [dynamic; 13]int append(&array, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9) - testing.expect(t, inject_at(&array, 0, 0), "Expected to be able to inject into small array") + testing.expect(t, inject_at(&array, 0, 0), "Expected to be able to inject into fixed capacity dynamic array") testing.expect(t, slice_equal(array[:], []int { 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 })) - testing.expect(t, inject_at(&array, 0, 5), "Expected to be able to inject into small array") + testing.expect(t, inject_at(&array, 0, 5), "Expected to be able to inject into fixed capacity dynamic array") testing.expect(t, slice_equal(array[:], []int { 0, 0, 1, 2, 3, 0, 4, 5, 6, 7, 8, 9 })) - testing.expect(t, inject_at(&array, 0, len(array)), "Expected to be able to inject into small array") + testing.expect(t, inject_at(&array, 0, len(array)), "Expected to be able to inject into fixed capacity dynamic array") testing.expect(t, slice_equal(array[:], []int { 0, 0, 1, 2, 3, 0, 4, 5, 6, 7, 8, 9, 0 })) } @@ -38,18 +38,21 @@ test_fixed_capacity_dynamic_array_inject_at :: proc(t: ^testing.T) { test_fixed_capacity_dynamic_array_push_back_elems :: proc(t: ^testing.T) { array: [dynamic; 2]int testing.expect(t, slice_equal(array[:], []int { })) - testing.expect(t, append(&array, 0), "Expected to be able to append to empty small array") + testing.expect(t, append(&array, 0) == 1, "Expected to be able to append to empty fixed capacity dynamic array") testing.expect(t, slice_equal(array[:], []int { 0 })) - testing.expect(t, append(&array, 1, 2) == false, "Expected to fail appending multiple elements beyond capacity of small array") - testing.expect(t, append(&array, 1), "Expected to be able to append to small array") + testing.expect(t, append(&array, 1) == 1, "Expected to be able to append to fixed capacity dynamic array") testing.expect(t, slice_equal(array[:], []int { 0, 1 })) - testing.expect(t, append(&array, 1) == false, "Expected to fail appending to full small array") - testing.expect(t, append(&array, 1, 2) == false, "Expected to fail appending multiple elements to full small array") + testing.expect(t, append(&array, 1, 2) == 1, "Expected to fail appending multiple elements beyond capacity of fixed capacity dynamic array") + clear(&array) + testing.expect(t, append(&array, 1) == 1, "Expected to be able to append to fixed capacity dynamic array") + testing.expect(t, append(&array, 2) == 1, "Expected to be able to append to fixed capacity dynamic array") + testing.expect(t, append(&array, 1) != 1, "Expected to fail appending to full fixed capacity dynamic array") + testing.expect(t, append(&array, 1, 2) != 2, "Expected to fail appending multiple elements to full fixed capacity dynamic array") clear(&array) testing.expect(t, slice_equal(array[:], []int { })) - testing.expect(t, append(&array, 1, 2, 3) == false, "Expected to fail appending multiple elements to empty small array") + testing.expect(t, append(&array, 1, 2, 3) != 3, "Expected to fail appending multiple elements to empty fixed capacity dynamic array") testing.expect(t, slice_equal(array[:], []int { })) - testing.expect(t, append(&array, 1, 2), "Expected to be able to append multiple elements to empty small array") + testing.expect(t, append(&array, 1, 2) == 2, "Expected to be able to append multiple elements to empty fixed capacity dynamic array") testing.expect(t, slice_equal(array[:], []int { 1, 2 })) }