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 61c3a6aad9
commit 0fdf2e7f3a

View File

@ -309,7 +309,7 @@ public class DefaultHttp2FrameWriter implements Http2FrameWriter, Http2FrameSize
try {
requireNonNull(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());