mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -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
|
v.size <- size
|
||||||
) else (
|
) else (
|
||||||
ensure_assuming_not_empty_ v size;
|
ensure_assuming_not_empty_ v size;
|
||||||
for i = v.size to size - 1 do
|
let {size=cur_size; vec} = v in
|
||||||
Array.unsafe_set v.vec i (f i)
|
for i = cur_size to size - 1 do
|
||||||
|
Array.unsafe_set vec i (f i)
|
||||||
done;
|
done;
|
||||||
|
assert (size <= Array.length v.vec);
|
||||||
v.size <- size
|
v.size <- size
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -146,6 +148,7 @@ let resize_with_init v ~init size =
|
||||||
v.size <- size
|
v.size <- size
|
||||||
) else (
|
) else (
|
||||||
ensure_assuming_not_empty_ v size;
|
ensure_assuming_not_empty_ v size;
|
||||||
|
(* nothing will change [v] *)
|
||||||
for i = v.size to size - 1 do
|
for i = v.size to size - 1 do
|
||||||
Array.unsafe_set v.vec i init
|
Array.unsafe_set v.vec i init
|
||||||
done;
|
done;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue