Skip to content

Commit c8a7789

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 b644ab6 commit c8a7789

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
@@ -1841,7 +1841,10 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
18411841

18421842
statistics_.data_received += nread;
18431843

1844-
if (UNLIKELY(stream_buf_offset_ > 0)) {
1844+
if (LIKELY(stream_buf_offset_ == 0)) {
1845+
// Shrink to the actual amount of used data.
1846+
buf.Resize(nread);
1847+
} else {
18451848
// This is a very unlikely case, and should only happen if the ReadStart()
18461849
// call in OnStreamAfterWrite() immediately provides data. If that does
18471850
// happen, we concatenate the data we received with the already-stored
@@ -1861,8 +1864,6 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
18611864
DecrementCurrentSessionMemory(stream_buf_.len);
18621865
}
18631866

1864-
// Shrink to the actual amount of used data.
1865-
buf.Resize(nread);
18661867
IncrementCurrentSessionMemory(nread);
18671868

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

0 commit comments

Comments
 (0)