Skip to content

Commit

Permalink
Replaced computeIfAbsent() with simpler alg: costly lambda creation
Browse files Browse the repository at this point in the history
  • Loading branch information
belaban committed Aug 27, 2024
1 parent 4e7b30d commit 3733c34
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/org/jgroups/util/MaxOneThreadPerSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ public MessageTable() {
}

protected Entry get(final Address sender, boolean multicast) {
return map.computeIfAbsent(sender, s -> new Entry(sender, multicast, tp.getClusterNameAscii()));
Entry e=map.get(sender);
if(e != null)
return e;
// not so elegant, but avoids lambda allocation!
Entry tmp=map.putIfAbsent(sender, (e=new Entry(sender, multicast, tp.getClusterNameAscii())));
return tmp!= null? tmp: e;
// return map.computeIfAbsent(sender, s -> new Entry(sender, multicast, tp.getClusterNameAscii()));
}

protected void clear() {map.clear();}
Expand Down

0 comments on commit 3733c34

Please sign in to comment.