Skip to content

Commit a343d35

Browse files
committed
http2: avoid unnecessary buffer resize
Refs: nodejs#34315 Refs: nodejs#30351
1 parent bfef588 commit a343d35

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/node_http2.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,10 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
17611761

17621762
statistics_.data_received += nread;
17631763

1764-
if (UNLIKELY(stream_buf_offset_ > 0)) {
1764+
if (LIKELY(stream_buf_offset_ == 0)) {
1765+
// Shrink to the actual amount of used data.
1766+
buf.Resize(nread);
1767+
} else {
17651768
// This is a very unlikely case, and should only happen if the ReadStart()
17661769
// call in OnStreamAfterWrite() immediately provides data. If that does
17671770
// happen, we concatenate the data we received with the already-stored
@@ -1782,8 +1785,6 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
17821785
DecrementCurrentSessionMemory(stream_buf_.len);
17831786
}
17841787

1785-
// Shrink to the actual amount of used data.
1786-
buf.Resize(nread);
17871788
IncrementCurrentSessionMemory(nread);
17881789

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

0 commit comments

Comments
 (0)