builtin: make array.ensure_cap/1 public

This commit is contained in:
Delyan Angelov 2025-06-18 08:56:48 +03:00
parent 37e5ead75d
commit d52bac1301
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED
2 changed files with 5 additions and 5 deletions

View file

@ -186,10 +186,10 @@ fn new_array_from_c_array_no_alloc(len int, cap int, elm_size int, c_array voidp
return arr return arr
} }
// Private function. Increases the `cap` of an array to the // ensure_cap increases the `cap` of an array to the required value
// required value by copying the data to a new memory location // by copying the data to a new memory location (creating a clone),
// (creating a clone) unless `a.cap` is already large enough. // unless `a.cap` is already large enough.
fn (mut a array) ensure_cap(required int) { pub fn (mut a array) ensure_cap(required int) {
if required <= a.cap { if required <= a.cap {
return return
} }

View file

@ -183,7 +183,7 @@ fn test_grow_len() {
assert sb.len == 20 assert sb.len == 20
assert sb.cap == 20 assert sb.cap == 20
unsafe { sb.ensure_cap(35) } sb.ensure_cap(35)
assert sb.len == 20 assert sb.len == 20
assert sb.cap == 35 assert sb.cap == 35