mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Minor change to shrink
This commit is contained in:
@@ -296,7 +296,7 @@ reserve_map :: proc(m: ^$T/map[$K]$V, capacity: int, loc := #caller_location) {
|
|||||||
/*
|
/*
|
||||||
Shrinks the capacity of a map down to the current length, or the given capacity.
|
Shrinks the capacity of a map down to the current length, or the given capacity.
|
||||||
|
|
||||||
If `new_cap` is -1, then `len(m)` is used.
|
If `new_cap` is negative, then `len(m)` is used.
|
||||||
|
|
||||||
Returns false if `cap(m) < new_cap`, or the allocator report failure.
|
Returns false if `cap(m) < new_cap`, or the allocator report failure.
|
||||||
|
|
||||||
@@ -305,7 +305,7 @@ reserve_map :: proc(m: ^$T/map[$K]$V, capacity: int, loc := #caller_location) {
|
|||||||
@builtin
|
@builtin
|
||||||
shrink_map :: proc(m: ^$T/map[$K]$V, new_cap := -1, loc := #caller_location) -> (did_shrink: bool) {
|
shrink_map :: proc(m: ^$T/map[$K]$V, new_cap := -1, loc := #caller_location) -> (did_shrink: bool) {
|
||||||
if m != nil {
|
if m != nil {
|
||||||
new_cap := new_cap if new_cap != -1 else len(m)
|
new_cap := new_cap if new_cap >= 0 else len(m)
|
||||||
return __dynamic_map_shrink(__get_map_header(m), new_cap, loc)
|
return __dynamic_map_shrink(__get_map_header(m), new_cap, loc)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -560,7 +560,7 @@ resize_dynamic_array :: proc(array: ^$T/[dynamic]$E, length: int, loc := #caller
|
|||||||
/*
|
/*
|
||||||
Shrinks the capacity of a dynamic array down to the current length, or the given capacity.
|
Shrinks the capacity of a dynamic array down to the current length, or the given capacity.
|
||||||
|
|
||||||
If `new_cap` is -1, then `len(array)` is used.
|
If `new_cap` is negative, then `len(array)` is used.
|
||||||
|
|
||||||
Returns false if `cap(array) < new_cap`, or the allocator report failure.
|
Returns false if `cap(array) < new_cap`, or the allocator report failure.
|
||||||
|
|
||||||
@@ -572,7 +572,7 @@ shrink_dynamic_array :: proc(array: ^$T/[dynamic]$E, new_cap := -1, loc := #call
|
|||||||
}
|
}
|
||||||
a := (^Raw_Dynamic_Array)(array)
|
a := (^Raw_Dynamic_Array)(array)
|
||||||
|
|
||||||
new_cap := new_cap if new_cap != -1 else a.len
|
new_cap := new_cap if new_cap >= 0 else a.len
|
||||||
|
|
||||||
if new_cap > a.cap {
|
if new_cap > a.cap {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user