Skip to content

Commit

Permalink
http2: avoid unnecessary buffer resize
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
lundibundi authored and mcollina committed Jul 27, 2020
1 parent 3e6b05e commit 62198d2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,10 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {

statistics_.data_received += nread;

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

// Shrink to the actual amount of used data.
buf.Resize(nread);
IncrementCurrentSessionMemory(nread);

// Remember the current buffer, so that OnDataChunkReceived knows the
Expand Down

0 comments on commit 62198d2

Please sign in to comment.