Skip to content

Commit

Permalink
Use result of Map.put as signal of existing entry
Browse files Browse the repository at this point in the history
 This is to reduce method count in the happy case
  • Loading branch information
tinnou committed Dec 18, 2023
1 parent 967ee4b commit 8da917a
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,11 @@ private void add(String s) {
// Lock to keep hashmap consistent with counter for remaining
lock.lock();
try {
if (remaining.get() > 0 && !values.containsKey(s)) {
values.put(s, s);
remaining.decrementAndGet();
if (remaining.get() > 0) {
String existing = values.put(s, s);
if (existing == null) {
remaining.decrementAndGet();
}
}
} finally {
lock.unlock();
Expand Down

0 comments on commit 8da917a

Please sign in to comment.