Improve SctpMessageCompletionHandler

Motivation:

Avoid multiple search in fragments map

Modifications:

Replace usage of Map.containsKey by Map.remove

Result:

During packet process, fragment is only search once in the map instead of 3 times in the previous worst case
This commit is contained in:
Frédérik Rouleau 2016-09-17 13:16:47 +02:00 committed by Norman Maurer
parent 4a5340eae7
commit 8d6f0a3ce4

View File

@ -43,10 +43,8 @@ public class SctpMessageCompletionHandler extends MessageToMessageDecoder<SctpMe
final boolean isComplete = msg.isComplete(); final boolean isComplete = msg.isComplete();
final boolean isUnordered = msg.isUnordered(); final boolean isUnordered = msg.isUnordered();
ByteBuf frag; ByteBuf frag = fragments.remove(streamIdentifier);
if (fragments.containsKey(streamIdentifier)) { if (frag == null) {
frag = fragments.remove(streamIdentifier);
} else {
frag = Unpooled.EMPTY_BUFFER; frag = Unpooled.EMPTY_BUFFER;
} }
@ -58,7 +56,6 @@ public class SctpMessageCompletionHandler extends MessageToMessageDecoder<SctpMe
fragments.put(streamIdentifier, Unpooled.wrappedBuffer(frag, byteBuf)); fragments.put(streamIdentifier, Unpooled.wrappedBuffer(frag, byteBuf));
} else if (isComplete && frag.isReadable()) { } else if (isComplete && frag.isReadable()) {
//last message to complete //last message to complete
fragments.remove(streamIdentifier);
SctpMessage assembledMsg = new SctpMessage( SctpMessage assembledMsg = new SctpMessage(
protocolIdentifier, protocolIdentifier,
streamIdentifier, streamIdentifier,