diff options
author | Brian White <mscdex@mscdex.net> | 2019-08-10 04:26:32 -0400 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-08-12 16:55:05 -0700 |
commit | 382f84a7f87296fe81e247051ccfc830d71fabca (patch) | |
tree | 20328c234ae4061c8b920438f6585bfc5a6e61ee /lib/internal/streams/buffer_list.js | |
parent | f114e5ba330a08803bb6dc7f16f20890ca493718 (diff) | |
download | android-node-v8-382f84a7f87296fe81e247051ccfc830d71fabca.tar.gz android-node-v8-382f84a7f87296fe81e247051ccfc830d71fabca.tar.bz2 android-node-v8-382f84a7f87296fe81e247051ccfc830d71fabca.zip |
stream: improve read() performance further
PR-URL: https://github.com/nodejs/node/pull/29077
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'lib/internal/streams/buffer_list.js')
-rw-r--r-- | lib/internal/streams/buffer_list.js | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/internal/streams/buffer_list.js b/lib/internal/streams/buffer_list.js index 36777ed82d..9d6e9e2fe4 100644 --- a/lib/internal/streams/buffer_list.js +++ b/lib/internal/streams/buffer_list.js @@ -71,19 +71,19 @@ module.exports = class BufferList { // Consumes a specified amount of bytes or characters from the buffered data. consume(n, hasStrings) { - var ret; - if (n < this.head.data.length) { + const data = this.head.data; + if (n < data.length) { // `slice` is the same for buffers and strings. - ret = this.head.data.slice(0, n); - this.head.data = this.head.data.slice(n); - } else if (n === this.head.data.length) { + const slice = data.slice(0, n); + this.head.data = data.slice(n); + return slice; + } + if (n === data.length) { // First chunk is a perfect match. - ret = this.shift(); - } else { - // Result spans more than one buffer. - ret = hasStrings ? this._getString(n) : this._getBuffer(n); + return this.shift(); } - return ret; + // Result spans more than one buffer. + return hasStrings ? this._getString(n) : this._getBuffer(n); } first() { |