grouped comptime param update
This commit is contained in:
@@ -23,8 +23,8 @@ deinit func($T type, list @mut ArrayList(T)) void {
|
||||
list.capacity = 0
|
||||
}
|
||||
|
||||
reserve func($T type, list @mut ArrayList(T), minimum_capacity usize) void ! mem.AllocError {
|
||||
if minimum_capacity <= list.capacity {
|
||||
reserve func($T type, list @mut ArrayList(T), min_capacity usize) void ! mem.AllocError {
|
||||
if min_capacity <= list.capacity {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -32,13 +32,13 @@ reserve func($T type, list @mut ArrayList(T), minimum_capacity usize) void ! mem
|
||||
if list.capacity >= 8 {
|
||||
half usize :: divtrunc!(list.capacity, 2)
|
||||
if list.capacity > maxval!(usize) - half {
|
||||
new_capacity = minimum_capacity
|
||||
new_capacity = min_capacity
|
||||
} else {
|
||||
new_capacity = list.capacity + half
|
||||
}
|
||||
}
|
||||
if new_capacity < minimum_capacity {
|
||||
new_capacity = minimum_capacity
|
||||
if new_capacity < min_capacity {
|
||||
new_capacity = min_capacity
|
||||
}
|
||||
|
||||
length usize :: list.items.len
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import "@std/mem"
|
||||
import "@std/testing"
|
||||
|
||||
handles_append test {
|
||||
list ArrayList(i32) = init(mem.c_allocator)
|
||||
defer deinit(&list)
|
||||
|
||||
try append(&list, 42)
|
||||
|
||||
try testing.expect_equal(1, list.items.len)
|
||||
try testing.expect_equal(42, list.items[0])
|
||||
}
|
||||
|
||||
handles_clear test {
|
||||
list ArrayList(i32) = init(mem.c_allocator)
|
||||
defer deinit(&list)
|
||||
|
||||
try append(&list, 42)
|
||||
clear(&list)
|
||||
|
||||
try testing.expect_equal(0, list.items.len)
|
||||
}
|
||||
|
||||
handles_reserve test {
|
||||
list ArrayList(i32) = init(mem.c_allocator)
|
||||
defer deinit(&list)
|
||||
|
||||
try reserve(&list, 10)
|
||||
|
||||
try testing.expect_equal(10, list.capacity)
|
||||
try testing.expect_equal(0, list.items.len)
|
||||
}
|
||||
Reference in New Issue
Block a user