From b8a5148569fd9b7f600eece53f57feeb337b8ad6 Mon Sep 17 00:00:00 2001 From: chenqwwq Date: Fri, 7 May 2021 17:37:30 +0800 Subject: [PATCH] Simplify ByteToMessageDecoder#callDecode (#11224) Motivation: After the if case, outSize is always 0, so we can simplify the code. Modification: Simplify code by not updating and using `isEmpty()`. Result: Clearer than before --- .../java/io/netty/handler/codec/ByteToMessageDecoder.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java b/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java index d32d0f9ae1..f83209855d 100644 --- a/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/ByteToMessageDecoder.java @@ -426,7 +426,7 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter protected void callDecode(ChannelHandlerContext ctx, ByteBuf in, List out) { try { while (in.isReadable()) { - int outSize = out.size(); + final int outSize = out.size(); if (outSize > 0) { fireChannelRead(ctx, out, outSize); @@ -440,7 +440,6 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter if (ctx.isRemoved()) { break; } - outSize = 0; } int oldInputLength = in.readableBytes(); @@ -454,7 +453,7 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter break; } - if (outSize == out.size()) { + if (out.isEmpty()) { if (oldInputLength == in.readableBytes()) { break; } else {