Skip to content
Permalink
Browse files

stream: improve read() performance further

PR-URL: #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>
  • Loading branch information...
mscdex authored and targos committed Aug 10, 2019
1 parent 3bfca0b commit 2a844599db8b7bdbe200358a6acb23ed30a38954
Showing with 10 additions and 10 deletions.
  1. +10 −10 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() {

0 comments on commit 2a84459

Please sign in to comment.
You can’t perform that action at this time.