buffer: improve copy() performance

There is no need to create a slice when sourceEnd is out of bounds.

PR-URL: https://github.com/nodejs/node/pull/33214
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Nikolai Vavilov authored and Anna Henningsen committed 2020-05-09 08:04:10 +02:00
1 parent ea465faf4a
commit 339690ce9b
1 file changed
+1 -1
+1 -1
View File
@@ -257,7 +257,7 @@ function _copyActual(source, target, targetStart, sourceStart, sourceEnd) {
if (nb > sourceLen)
nb = sourceLen;
if (sourceStart !== 0 || sourceEnd !== source.length)
if (sourceStart !== 0 || sourceEnd < source.length)
source = new Uint8Array(source.buffer, source.byteOffset + sourceStart, nb);
target.set(source, targetStart);