Skip to content

Commit 5b7315f

Browse files
committed
[perf] Use TypedArray#set() instead of Buffer#copy()
1 parent 74bac8e commit 5b7315f

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/buffer-util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function concat(list, totalLength) {
1919

2020
for (let i = 0; i < list.length; i++) {
2121
const buf = list[i];
22-
buf.copy(target, offset);
22+
target.set(buf, offset);
2323
offset += buf.length;
2424
}
2525

lib/receiver.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ class Receiver extends Writable {
9696

9797
do {
9898
const buf = this._buffers[0];
99+
const offset = dst.length - n;
99100

100101
if (n >= buf.length) {
101-
this._buffers.shift().copy(dst, dst.length - n);
102+
dst.set(this._buffers.shift(), offset);
102103
} else {
103-
buf.copy(dst, dst.length - n, 0, n);
104+
dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
104105
this._buffers[0] = buf.slice(n);
105106
}
106107

0 commit comments

Comments
 (0)