Skip to content

Commit 8843a5a

Browse files
committed
Use saturating addition
1 parent 5e6a9e7 commit 8843a5a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

crates/oxc_allocator/src/tracking.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@ pub struct AllocationStats {
3434
impl AllocationStats {
3535
/// Record that an allocation was made.
3636
pub(crate) fn record_allocation(&self) {
37-
self.num_alloc.set(self.num_alloc.get() + 1);
37+
// Counter maxes out at `usize::MAX`, but if there's that many allocations,
38+
// the exact number is not important
39+
self.num_alloc.set(self.num_alloc.get().saturating_add(1));
3840
}
3941

4042
/// Record that a reallocation was made.
4143
pub(crate) fn record_reallocation(&self) {
42-
self.num_realloc.set(self.num_realloc.get() + 1);
44+
// Counter maxes out at `usize::MAX`, but if there's that many allocations,
45+
// the exact number is not important
46+
self.num_realloc.set(self.num_realloc.get().saturating_add(1));
4347
}
4448

4549
/// Reset allocation counters.

0 commit comments

Comments
 (0)