mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-06 03:05:31 -05:00
change strategy for vec reallocation
This commit is contained in:
parent
6be7e7c71a
commit
7407669834
1 changed files with 3 additions and 1 deletions
|
|
@ -69,13 +69,15 @@ let grow_to_double_size t =
|
|||
let size = min Sys.max_array_length (2* Array.length t.data + 1) in
|
||||
grow_to_exact t size
|
||||
|
||||
(* grow to at least [new_capa] by increments of
|
||||
approximately [new_size = old_size * 1.5] *)
|
||||
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
|
||||
while !capa < new_capa do
|
||||
capa := min (2 * !capa + 1) Sys.max_array_length;
|
||||
capa := min (!capa + (!capa lsr 1) + 2) Sys.max_array_length;
|
||||
done;
|
||||
grow_to_exact t !capa
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue