Skip to content

Commit

Permalink
eliminate boxing in RequesterResponderSupport when using IntObjectMap
Browse files Browse the repository at this point in the history
  • Loading branch information
olme04 committed Nov 10, 2021
1 parent efd1269 commit 32332b9
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.rsocket.RSocket;
import io.rsocket.frame.decoder.PayloadDecoder;
import io.rsocket.plugins.RequestInterceptor;
import java.util.Objects;
import java.util.function.Function;
import reactor.util.annotation.Nullable;

Expand Down Expand Up @@ -118,8 +119,12 @@ public int addAndGetNextStreamId(FrameHandler frameHandler) {
}

public synchronized boolean add(int streamId, FrameHandler frameHandler) {
final FrameHandler previousHandler = this.activeStreams.putIfAbsent(streamId, frameHandler);

final IntObjectMap<FrameHandler> activeStreams = this.activeStreams;
// copy of Map.putIfAbsent(key, value) without `streamId` boxing
FrameHandler previousHandler = activeStreams.get(streamId);
if (previousHandler == null) {
previousHandler = activeStreams.put(streamId, frameHandler);
}
return previousHandler == null;
}

Expand All @@ -143,6 +148,13 @@ public synchronized FrameHandler get(int streamId) {
* instance equals to the passed one
*/
public synchronized boolean remove(int streamId, FrameHandler frameHandler) {
return this.activeStreams.remove(streamId, frameHandler);
final IntObjectMap<FrameHandler> activeStreams = this.activeStreams;
// copy of Map.remove(key, value) without `streamId` boxing
final FrameHandler curValue = activeStreams.get(streamId);
if (!Objects.equals(curValue, frameHandler)) {
return false;
}
activeStreams.remove(streamId);
return true;
}
}

0 comments on commit 32332b9

Please sign in to comment.