Skip to content

Commit

Permalink
call invalid_arg, rearrange branching
Browse files Browse the repository at this point in the history
  • Loading branch information
RadioPotin committed Oct 20, 2021
1 parent 69a6d42 commit 4114f1a
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/core/CCVector.ml
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,15 @@ let push v x =

let resize_with v f size =
if size > Sys.max_array_length then
raise (Invalid_argument "vec.resize_with: size too big")
else if size <= Array.length v.vec then
()
else
invalid_arg "vec.resize_with: size too big"
else if size > Array.length v.vec then
let new_vec = Array.make size (f 0) in
Array.blit v.vec 0 new_vec 0 (v.size - 1);
for i = v.size to size - 1 do
Array.unsafe_set new_vec i (f i)
done;
v.vec <- new_vec;
v.size <- size;
()
v.size <- size

(*$T
let v = make 1 0 in to_list (resize_with v (fun i -> i) 5) = [0;1;2;3;4]
Expand All @@ -228,15 +225,12 @@ let resize_with v f size =

let resize_with_init v ~init size =
if size > Sys.max_array_length then
raise (Invalid_argument "vec.resize_with_init: size too big")
else if size <= Array.length v.vec then
()
else
invalid_arg "vec.resize_with_init: size too big"
else if size > Array.length v.vec then
let new_vec = Array.make size init in
Array.blit v.vec 0 new_vec 0 (v.size - 1);
v.vec <- new_vec;
v.size <- size;
()
v.size <- size

(*$T
let v = make 1 0 in to_list (resize_with_init v ~init:1 5) = [1;1;1;1;1]
Expand Down

0 comments on commit 4114f1a

Please sign in to comment.