Avoid unnecessary call to ByteBuf.isReadable() from ByteToMessageDecoder

Motivation:

This will avoid one unncessary method invokation which will slightly improve performance.

Modifications:

Instead of calling isReadable we just check for the value of readableBytes()

Result:

Nothing functionally speaking change.
This commit is contained in:
Cristian 2015-02-15 21:36:43 -08:00 committed by Norman Maurer
parent 489f2e1d75
commit 37cca81f1c

View File

@ -98,7 +98,7 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter
/** /**
* Cumulate {@link ByteBuf}s by add them to a {@link CompositeByteBuf} and so do no memory copy whenever possible. * Cumulate {@link ByteBuf}s by add them to a {@link CompositeByteBuf} and so do no memory copy whenever possible.
* Be aware that {@link CompositeByteBuf} use a more complex indexing implementation so depending on your use-case * Be aware that {@link CompositeByteBuf} use a more complex indexing implementation so depending on your use-case
* and the decoder implemention this may be slower then just use the {@link #MERGE_CUMULATOR}. * and the decoder implementation this may be slower then just use the {@link #MERGE_CUMULATOR}.
*/ */
public static final Cumulator COMPOSITE_CUMULATOR = new Cumulator() { public static final Cumulator COMPOSITE_CUMULATOR = new Cumulator() {
@Override @Override
@ -196,7 +196,7 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter
public final void handlerRemoved(ChannelHandlerContext ctx) throws Exception { public final void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
ByteBuf buf = internalBuffer(); ByteBuf buf = internalBuffer();
int readable = buf.readableBytes(); int readable = buf.readableBytes();
if (buf.isReadable()) { if (readable > 0) {
ByteBuf bytes = buf.readBytes(readable); ByteBuf bytes = buf.readBytes(readable);
buf.release(); buf.release();
ctx.fireChannelRead(bytes); ctx.fireChannelRead(bytes);