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 c4d69e982b
commit 891be30a28

View File

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