Skip to content

Commit

Permalink
Skip calling Compute in RemoveSafeDeltaCounterCell if value exists (#…
Browse files Browse the repository at this point in the history
…30913)

* Skip calling Compute in RemoveSafeDeltaCounterCell if value already exists

* Address comments
  • Loading branch information
JayajP authored Apr 16, 2024
1 parent ae597cc commit ec31847
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,12 @@ public void reset() {

@Override
public void inc(long n) {
countersMap.compute(
metricName,
(name, value) -> {
if (value == null) {
return new AtomicLong(n);
}
value.addAndGet(n);
return value;
});
AtomicLong val = countersMap.get(metricName);
if (val != null) {
val.getAndAdd(n);
return;
}
countersMap.computeIfAbsent(metricName, name -> new AtomicLong()).getAndAdd(n);
}

@Override
Expand Down

0 comments on commit ec31847

Please sign in to comment.