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 <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
  • Loading branch information
lundibundi authored and codebytere committed Nov 2, 2020
1 parent 5cb86f2 commit 8d8d2b4
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 @@ -1841,7 +1841,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 @@ -1861,8 +1864,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 8d8d2b4

Please sign in to comment.