Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eliminate boxing in RequesterResponderSupport when using IntObjectMap #1029

Merged
merged 1 commit into from
Nov 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,9 +119,14 @@ public int addAndGetNextStreamId(FrameHandler frameHandler) {
}

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

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

/**
Expand All @@ -143,6 +149,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;
}
}