From 8d7ffec081ac00192dbe3f07972471ec7d1a3933 Mon Sep 17 00:00:00 2001 From: Liyuan Date: Sun, 18 Apr 2021 10:25:25 -0700 Subject: [PATCH] Used already calculated SETTINGS frame payload length when allocating ByteBuf Motivation: We have already calculated the payload length. So no need to calculate again when allocating ByteBuf Modification: Used payloadLength variable instead of calculating the payload length again Result: Re-use the variable value and make the code cleaner --- .../io/netty/handler/codec/http2/DefaultHttp2FrameWriter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameWriter.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameWriter.java index e13a631c31..6ef92018bc 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameWriter.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameWriter.java @@ -310,7 +310,7 @@ public class DefaultHttp2FrameWriter implements Http2FrameWriter, Http2FrameSize try { checkNotNull(settings, "settings"); int payloadLength = SETTING_ENTRY_LENGTH * settings.size(); - ByteBuf buf = ctx.alloc().buffer(FRAME_HEADER_LENGTH + settings.size() * SETTING_ENTRY_LENGTH); + ByteBuf buf = ctx.alloc().buffer(FRAME_HEADER_LENGTH + payloadLength); writeFrameHeaderInternal(buf, payloadLength, SETTINGS, new Http2Flags(), 0); for (Http2Settings.PrimitiveEntry entry : settings.entries()) { buf.writeChar(entry.key());