Skip to content

Commit

Permalink
buffer: use native copy impl
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Jul 28, 2024
1 parent 8a41d9b commit ce07761
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const {
byteLengthUtf8,
compare: _compare,
compareOffset,
copyArrayBuffer,
createFromString,
fill: bindingFill,
isAscii: bindingIsAscii,
Expand Down Expand Up @@ -248,10 +249,20 @@ function _copyActual(source, target, targetStart, sourceStart, sourceEnd) {
if (nb > sourceLen)
nb = sourceLen;

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

TypedArrayPrototypeSet(target, source, targetStart);
if (sourceStart !== 0 || sourceEnd < source.length) {
copyArrayBuffer(
target.buffer,
target.byteOffset + targetStart,
source.buffer,
source.byteOffset + sourceStart,
nb,
);
} else {
TypedArrayPrototypeSet(target, source, targetStart);
}

return nb;
}
Expand Down

0 comments on commit ce07761

Please sign in to comment.