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 147b14d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 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,17 @@ 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);

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 147b14d

Please sign in to comment.