Skip to content

Commit eccbfc7

Browse files
committed
Minor optimization to Size
There is no need to mask the counters outside of snapshotting.
1 parent e2822ff commit eccbfc7

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src_lockfree/size.ml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module Snapshot = struct
4444

4545
let[@inline] set s i after =
4646
let snap = Array.unsafe_get s i in
47+
let after = after land max_value in
4748
let before = Atomic.get snap in
4849
if
4950
before = collecting
@@ -53,6 +54,7 @@ module Snapshot = struct
5354

5455
let[@inline] forward s i after =
5556
let snap = Array.unsafe_get s i in
57+
let after = after land max_value in
5658
while
5759
let before = Atomic.get snap in
5860
(before = collecting
@@ -170,21 +172,18 @@ let new_once t update =
170172
let rec update_once txs once counter =
171173
let before = Atomic.get counter in
172174
let index = get_index once in
173-
let before_once = before.once in
174-
if index != used_index && before_once != once then begin
175-
use_index before_once;
176-
let value = (before.value + 1) land max_value in
177-
let after = { value; once } in
175+
if index != used_index && before.once != once then begin
176+
use_index before.once;
177+
let after = { value = before.value + 1; once } in
178178
if Atomic.compare_and_set counter before after then begin
179179
let snapshot = Atomic.get (snapshot_of txs) in
180180
if Snapshot.is_collecting snapshot then
181-
Snapshot.forward snapshot index value
181+
Snapshot.forward snapshot index after.value
182182
end
183183
else update_once txs once (Array.unsafe_get txs index)
184184
end
185185

186-
let update_once t once =
187-
match once with
186+
let update_once t = function
188187
| Once Used -> ()
189188
| Once (Open _ as once) ->
190189
let index = get_index once in

0 commit comments

Comments
 (0)