Skip to content

Commit 098b193

Browse files
lundibundiMylesBorins
authored andcommitted
http2: avoid unnecessary buffer resize
Refs: #34315 Refs: #30351 PR-URL: #34480 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: David Carlier <[email protected]>
1 parent a4806e2 commit 098b193

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/node_http2.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,10 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
17541754

17551755
statistics_.data_received += nread;
17561756

1757-
if (UNLIKELY(stream_buf_offset_ > 0)) {
1757+
if (LIKELY(stream_buf_offset_ == 0)) {
1758+
// Shrink to the actual amount of used data.
1759+
buf.Resize(nread);
1760+
} else {
17581761
// This is a very unlikely case, and should only happen if the ReadStart()
17591762
// call in OnStreamAfterWrite() immediately provides data. If that does
17601763
// happen, we concatenate the data we received with the already-stored
@@ -1775,8 +1778,6 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
17751778
DecrementCurrentSessionMemory(stream_buf_.len);
17761779
}
17771780

1778-
// Shrink to the actual amount of used data.
1779-
buf.Resize(nread);
17801781
IncrementCurrentSessionMemory(nread);
17811782

17821783
// Remember the current buffer, so that OnDataChunkReceived knows the

0 commit comments

Comments
 (0)