Skip to content

Commit ce07761

Browse files
committed
buffer: use native copy impl
1 parent 8a41d9b commit ce07761

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/buffer.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const {
5858
byteLengthUtf8,
5959
compare: _compare,
6060
compareOffset,
61+
copyArrayBuffer,
6162
createFromString,
6263
fill: bindingFill,
6364
isAscii: bindingIsAscii,
@@ -248,10 +249,20 @@ function _copyActual(source, target, targetStart, sourceStart, sourceEnd) {
248249
if (nb > sourceLen)
249250
nb = sourceLen;
250251

251-
if (sourceStart !== 0 || sourceEnd < source.length)
252-
source = new Uint8Array(source.buffer, source.byteOffset + sourceStart, nb);
252+
if (nb <= 0)
253+
return 0;
253254

254-
TypedArrayPrototypeSet(target, source, targetStart);
255+
if (sourceStart !== 0 || sourceEnd < source.length) {
256+
copyArrayBuffer(
257+
target.buffer,
258+
target.byteOffset + targetStart,
259+
source.buffer,
260+
source.byteOffset + sourceStart,
261+
nb,
262+
);
263+
} else {
264+
TypedArrayPrototypeSet(target, source, targetStart);
265+
}
255266

256267
return nb;
257268
}

0 commit comments

Comments
 (0)