From 147b14dc7d07e0f481550a0783c048701aef5b97 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sun, 28 Jul 2024 23:14:29 +0200 Subject: [PATCH] buffer: use native copy impl --- lib/buffer.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/buffer.js b/lib/buffer.js index 59a125960c276f..19261b9ad26e75 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -58,6 +58,7 @@ const { byteLengthUtf8, compare: _compare, compareOffset, + copyArrayBuffer, createFromString, fill: bindingFill, isAscii: bindingIsAscii, @@ -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; }