0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-28 22:46:31 +01:00

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 2020-05-02 20:30:44 +03:00 committed by Anna Henningsen
parent ea465faf4a
commit 339690ce9b
No known key found for this signature in database
GPG Key ID: A94130F0BFC8EBE9

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);