From 339690ce9b78da84bf9ea1b4dc9107da91ee4041 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 874227f0d44..a818f41a26e 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);