Remove memory copy when extract frame in LengthFieldBasedFrameDecoder

Motivation:

We are currently doing a memory cop to extract the frame in LengthFieldBasedFrameDecoder which can be eliminated.

Modifications:

Use buffer.slice(...).retain() to eliminate the memory copy.

Result:

Better performance.
This commit is contained in:
Norman Maurer 2015-04-27 15:14:01 +02:00
parent 5a9da7c5ba
commit 4c70a99e5a

View File

@ -491,9 +491,7 @@ public class LengthFieldBasedFrameDecoder extends ByteToMessageDecoder {
* is overridden to avoid memory copy.
*/
protected ByteBuf extractFrame(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length) {
ByteBuf frame = ctx.alloc().buffer(length);
frame.writeBytes(buffer, index, length);
return frame;
return buffer.slice(index, length).retain();
}
private void fail(long frameLength) {