mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-05 19:00:31 -05:00
fix(CCVector): concurrent modification safety in resize_with
This commit is contained in:
parent
b73fc4ee5c
commit
b1c39832aa
1 changed files with 5 additions and 2 deletions
|
|
@ -132,9 +132,11 @@ let resize_with v f size =
|
|||
v.size <- size
|
||||
) else (
|
||||
ensure_assuming_not_empty_ v size;
|
||||
for i = v.size to size - 1 do
|
||||
Array.unsafe_set v.vec i (f i)
|
||||
let {size=cur_size; vec} = v in
|
||||
for i = cur_size to size - 1 do
|
||||
Array.unsafe_set vec i (f i)
|
||||
done;
|
||||
assert (size <= Array.length v.vec);
|
||||
v.size <- size
|
||||
)
|
||||
|
||||
|
|
@ -146,6 +148,7 @@ let resize_with_init v ~init size =
|
|||
v.size <- size
|
||||
) else (
|
||||
ensure_assuming_not_empty_ v size;
|
||||
(* nothing will change [v] *)
|
||||
for i = v.size to size - 1 do
|
||||
Array.unsafe_set v.vec i init
|
||||
done;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue