Skip to content

Commit

Permalink
Replace the type of messageMap with IntObjectMap.
Browse files Browse the repository at this point in the history
  • Loading branch information
seedeed committed Feb 24, 2020
1 parent 5c458c9 commit 8565edc
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.spdy.SpdyHttpHeaders.Names;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.collection.IntObjectHashMap;
import io.netty.util.collection.IntObjectMap;
import io.netty.util.internal.ObjectUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -50,7 +51,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyFrame> {
private final boolean validateHeaders;
private final int spdyVersion;
private final int maxContentLength;
private final Map<Integer, FullHttpMessage> messageMap;
private final IntObjectMap<FullHttpMessage> messageMap;

/**
* Creates a new instance.
Expand All @@ -61,7 +62,7 @@ public class SpdyHttpDecoder extends MessageToMessageDecoder<SpdyFrame> {
* a {@link TooLongFrameException} will be raised.
*/
public SpdyHttpDecoder(SpdyVersion version, int maxContentLength) {
this(version, maxContentLength, new HashMap<Integer, FullHttpMessage>(), true);
this(version, maxContentLength, new IntObjectHashMap<FullHttpMessage>(), true);
}

/**
Expand All @@ -74,7 +75,7 @@ public SpdyHttpDecoder(SpdyVersion version, int maxContentLength) {
* @param validateHeaders {@code true} if http headers should be validated
*/
public SpdyHttpDecoder(SpdyVersion version, int maxContentLength, boolean validateHeaders) {
this(version, maxContentLength, new HashMap<Integer, FullHttpMessage>(), validateHeaders);
this(version, maxContentLength, new IntObjectHashMap<FullHttpMessage>(), validateHeaders);
}

/**
Expand Down Expand Up @@ -104,10 +105,20 @@ protected SpdyHttpDecoder(SpdyVersion version, int maxContentLength, Map<Integer
FullHttpMessage> messageMap, boolean validateHeaders) {
spdyVersion = ObjectUtil.checkNotNull(version, "version").getVersion();
this.maxContentLength = checkPositive(maxContentLength, "maxContentLength");
this.messageMap = messageMap;
this.messageMap = newMessageMap(ObjectUtil.checkNotNull(messageMap, "messageMap"));
this.validateHeaders = validateHeaders;
}

private static IntObjectMap<FullHttpMessage> newMessageMap(Map<Integer,
FullHttpMessage> messageMap) {
if (messageMap instanceof IntObjectMap) {
return (IntObjectMap<FullHttpMessage>) messageMap;
}
IntObjectHashMap<FullHttpMessage> newMessageMap = new IntObjectHashMap<FullHttpMessage>(messageMap.size());
newMessageMap.putAll(messageMap);
return newMessageMap;
}

@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
// Release any outstanding messages from the map
Expand Down

0 comments on commit 8565edc

Please sign in to comment.