Skip to content

Commit 2a84459

Browse files
mscdextargos
authored andcommitted
stream: improve read() performance further
PR-URL: #29077 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 3bfca0b commit 2a84459

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

lib/internal/streams/buffer_list.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ module.exports = class BufferList {
7171

7272
// Consumes a specified amount of bytes or characters from the buffered data.
7373
consume(n, hasStrings) {
74-
var ret;
75-
if (n < this.head.data.length) {
74+
const data = this.head.data;
75+
if (n < data.length) {
7676
// `slice` is the same for buffers and strings.
77-
ret = this.head.data.slice(0, n);
78-
this.head.data = this.head.data.slice(n);
79-
} else if (n === this.head.data.length) {
77+
const slice = data.slice(0, n);
78+
this.head.data = data.slice(n);
79+
return slice;
80+
}
81+
if (n === data.length) {
8082
// First chunk is a perfect match.
81-
ret = this.shift();
82-
} else {
83-
// Result spans more than one buffer.
84-
ret = hasStrings ? this._getString(n) : this._getBuffer(n);
83+
return this.shift();
8584
}
86-
return ret;
85+
// Result spans more than one buffer.
86+
return hasStrings ? this._getString(n) : this._getBuffer(n);
8787
}
8888

8989
first() {

0 commit comments

Comments
 (0)