http2: avoid unnecessary buffer resize

Refs: https://github.com/nodejs/node/pull/34315
Refs: https://github.com/nodejs/node/pull/30351

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Denys Otrishko authored and Matteo Collina committed 2020-07-27 15:41:41 +02:00
1 parent 3e6b05e1aa
commit 62198d2d17
1 file changed
+4 -3
+4 -3
View File
@@ -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
@@ -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