Skip to content

Commit

Permalink
buffer: faster integer argument check
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Jul 28, 2024
1 parent 8a41d9b commit 8ff2f40
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const {
MathFloor,
MathMin,
MathTrunc,
NumberIsInteger,
NumberIsNaN,
NumberMAX_SAFE_INTEGER,
NumberMIN_SAFE_INTEGER,
Expand Down Expand Up @@ -212,23 +213,23 @@ function _copy(source, target, targetStart, sourceStart, sourceEnd) {
if (targetStart === undefined) {
targetStart = 0;
} else {
targetStart = toInteger(targetStart, 0);
targetStart = NumberIsInteger(targetStart) ? targetStart : toInteger(targetStart, 0);
if (targetStart < 0)
throw new ERR_OUT_OF_RANGE('targetStart', '>= 0', targetStart);
}

if (sourceStart === undefined) {
sourceStart = 0;
} else {
sourceStart = toInteger(sourceStart, 0);
sourceStart = NumberIsInteger(targetStart) ? targetStart : toInteger(sourceStart, 0);
if (sourceStart < 0 || sourceStart > source.length)
throw new ERR_OUT_OF_RANGE('sourceStart', `>= 0 && <= ${source.length}`, sourceStart);
}

if (sourceEnd === undefined) {
sourceEnd = source.length;
} else {
sourceEnd = toInteger(sourceEnd, 0);
sourceEnd = NumberIsInteger(sourceEnd) ? sourceEnd : toInteger(sourceEnd, 0);
if (sourceEnd < 0)
throw new ERR_OUT_OF_RANGE('sourceEnd', '>= 0', sourceEnd);
}
Expand Down

0 comments on commit 8ff2f40

Please sign in to comment.