From cae2051b832d6f836d6ab9bc5752113fc01fc0c8 Mon Sep 17 00:00:00 2001 From: Nikolai Vavilov Date: Sat, 2 May 2020 20:30:44 +0300 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig Reviewed-By: Zeyu Yang Reviewed-By: Luigi Pinca --- lib/buffer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/buffer.js b/lib/buffer.js index 874227f0d44051..a818f41a26ed5b 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -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);