Skip to content

Commit

Permalink
buffer: improve copy() performance
Browse files Browse the repository at this point in the history
There is no need to create a slice when sourceEnd is out of bounds.

PR-URL: #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>
  • Loading branch information
seishun authored and codebytere committed May 11, 2020
1 parent eedc131 commit cae2051
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit cae2051

Please sign in to comment.