enforce integer division via explicit builtins
This commit is contained in:
@@ -30,7 +30,7 @@ reserve func($T type, list @mut ArrayList(T), minimum_capacity usize) void ! mem
|
||||
|
||||
new_capacity usize = 8
|
||||
if list.capacity >= 8 {
|
||||
half usize :: list.capacity / 2
|
||||
half usize :: div_trunc(list.capacity, 2)
|
||||
if list.capacity > max_value(usize) - half {
|
||||
new_capacity = minimum_capacity
|
||||
} else {
|
||||
|
||||
+3
-3
@@ -61,7 +61,7 @@ alloc func($T type, allocator Allocator, count usize) []mut T ! AllocError {
|
||||
if element_size == 0 {
|
||||
return _empty_slice(T, count)
|
||||
}
|
||||
if count > max_value(usize) / element_size {
|
||||
if count > div_trunc(max_value(usize), element_size) {
|
||||
return .out_of_memory
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ realloc func($T type, allocator Allocator, memory []mut T, new_count usize) []mu
|
||||
if element_size == 0 {
|
||||
return _empty_slice(T, new_count)
|
||||
}
|
||||
if new_count > max_value(usize) / element_size {
|
||||
if new_count > div_trunc(max_value(usize), element_size) {
|
||||
return .out_of_memory
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ _power_of_two func(value usize) bool {
|
||||
|
||||
current usize = value
|
||||
while current > 1 {
|
||||
half usize = current / 2
|
||||
half usize = div_trunc(current, 2)
|
||||
if half * 2 != current {
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user