mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-08 12:15:48 -05:00
avoid allocating at every call to grow_to_at_least
This commit is contained in:
parent
2e7e947b62
commit
30832099b3
1 changed files with 4 additions and 2 deletions
|
|
@ -73,11 +73,13 @@ let grow_to_at_least t new_capa =
|
|||
assert (new_capa >= 0);
|
||||
if new_capa > Sys.max_array_length then _size_too_big ();
|
||||
let data = t.data in
|
||||
let capa = ref (Array.length data + 1) in
|
||||
let capa = ref (max (Array.length data) 1) in
|
||||
while !capa < new_capa do
|
||||
capa := min (2 * !capa + 1) Sys.max_array_length;
|
||||
done;
|
||||
if !capa > Array.length data then (
|
||||
grow_to_exact t !capa
|
||||
)
|
||||
|
||||
let is_full t = Array.length t.data = t.sz
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue