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
This commit is contained in:
Liyuan 2021-04-18 10:25:25 -07:00 committed by Norman Maurer
parent e27831d767
commit 8d7ffec081

View File

@ -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<Long> entry : settings.entries()) {
buf.writeChar(entry.key());