Skip to content

Commit

Permalink
http2: avoid unnecessary buffer resize
Browse files Browse the repository at this point in the history
  • Loading branch information
lundibundi committed Jul 22, 2020
1 parent bfef588 commit a343d35
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 a343d35

Please sign in to comment.