Skip to content

Commit 30d87a2

Browse files
authored
Merge pull request #6324 from Faker-09/dynamic_array_move_assert
Small optimization for dynamic arrays
2 parents b26b9bd + 3fd9c91 commit 30d87a2

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

base/runtime/core_builtin.odin

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -893,8 +893,8 @@ _reserve_dynamic_array :: #force_no_inline proc(a: ^Raw_Dynamic_Array, size_of_e
893893

894894
if a.allocator.procedure == nil {
895895
a.allocator = context.allocator
896+
assert(a.allocator.procedure != nil)
896897
}
897-
assert(a.allocator.procedure != nil)
898898

899899
old_size := a.cap * size_of_elem
900900
new_size := capacity * size_of_elem
@@ -953,8 +953,8 @@ _resize_dynamic_array :: #force_no_inline proc(a: ^Raw_Dynamic_Array, size_of_el
953953

954954
if a.allocator.procedure == nil {
955955
a.allocator = context.allocator
956+
assert(a.allocator.procedure != nil)
956957
}
957-
assert(a.allocator.procedure != nil)
958958

959959
old_size := a.cap * size_of_elem
960960
new_size := length * size_of_elem
@@ -1023,8 +1023,8 @@ _shrink_dynamic_array :: proc(a: ^Raw_Dynamic_Array, size_of_elem, align_of_elem
10231023

10241024
if a.allocator.procedure == nil {
10251025
a.allocator = context.allocator
1026+
assert(a.allocator.procedure != nil)
10261027
}
1027-
assert(a.allocator.procedure != nil)
10281028

10291029
old_size := a.cap * size_of_elem
10301030
new_size := new_cap * size_of_elem

base/runtime/core_builtin_soa.odin

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ make_soa_aligned :: proc($T: typeid/#soa[]$E, #any_int length, alignment: int, a
105105
allocator := allocator
106106
if allocator.procedure == nil {
107107
allocator = context.allocator
108+
assert(allocator.procedure != nil)
108109
}
109-
assert(allocator.procedure != nil)
110110

111111
new_bytes: []byte
112112
new_bytes, err = allocator.procedure(
@@ -240,8 +240,8 @@ _reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, capacity: int, zero_memory: boo
240240

241241
if array.allocator.procedure == nil {
242242
array.allocator = context.allocator
243+
assert(array.allocator.procedure != nil)
243244
}
244-
assert(array.allocator.procedure != nil)
245245

246246
footer := raw_soa_footer(array)
247247
if size_of(E) == 0 {

base/runtime/dynamic_array_internal.odin

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ __dynamic_array_reserve :: proc(array_: rawptr, elem_size, elem_align: int, cap:
1818
// assuming that appending/reserving will set the allocator, if it is not already set.
1919
if array.allocator.procedure == nil {
2020
array.allocator = context.allocator
21+
assert(array.allocator.procedure != nil)
2122
}
22-
assert(array.allocator.procedure != nil)
2323

2424
if cap <= array.cap {
2525
return true
@@ -52,8 +52,8 @@ __dynamic_array_shrink :: proc(array_: rawptr, elem_size, elem_align: int, new_c
5252
// assuming that appending/reserving will set the allocator, if it is not already set.
5353
if array.allocator.procedure == nil {
5454
array.allocator = context.allocator
55+
assert(array.allocator.procedure != nil)
5556
}
56-
assert(array.allocator.procedure != nil)
5757

5858
if new_cap > array.cap {
5959
return

0 commit comments

Comments
 (0)