Implement suggested change (risky Cons {a;n;tl} -> Cons r)

This commit is contained in:
ilo Kali 2024-01-09 16:22:16 -05:00 committed by GitHub
parent 3f14750a3b
commit 5b651084f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -204,7 +204,7 @@ module MList = struct
| _ -> | _ ->
match !tail with match !tail with
| Nil -> () | Nil -> ()
| Cons (_ as r) -> r.tl <- !cur | Cons r -> r.tl <- !cur
in in
seq (fun x -> seq (fun x ->
@ -215,11 +215,11 @@ module MList = struct
let n = !chunk_size in let n = !chunk_size in
if n < 4096 then chunk_size := 2 * n; if n < 4096 then chunk_size := 2 * n;
cur := Cons {a=Array.make n x; n = 1; tl = Nil} cur := Cons {a=Array.make n x; n = 1; tl = Nil}
| Cons ({a; n; tl} as r) -> | Cons r ->
assert (n < Array.length a); assert (r.n < Array.length r.a);
a.(n) <- x; r.a.(r.n) <- x;
r.n <- succ n; r.n <- succ r.n;
if r.n = Array.length a then ( if r.n = Array.length r.a then (
replace_tail (); replace_tail ();
tail := !cur; tail := !cur;
cur := Nil cur := Nil