Commit c2d9df5f authored by POTTIER Francois's avatar POTTIER Francois

Speed improvement in [CompressedBitSet.fold].

Move call to [fold f qs] into loop, making it tail-recursive.
Then, hoist [loop] out of [fold].
The impact is measurable on [Coverage] (maybe 10% overall).
parent 79a9ec1e
......@@ -89,13 +89,13 @@ let rec fold f s accu =
accu
| C (base, ss, qs) ->
let limit = base + word_size in
let rec loop i ss accu =
if i = limit then
accu
else
loop (i + 1) (ss lsr 1) (if ss land 1 = 1 then f i accu else accu)
in
fold f qs (loop base ss accu)
loop limit f qs base ss accu
and loop limit f qs i ss accu =
if i = limit then
fold f qs accu
else
loop limit f qs (i + 1) (ss lsr 1) (if ss land 1 = 1 then f i accu else accu)
let iter f s =
fold (fun x () -> f x) s ()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment