Skip to content

Commit

Permalink
buffer: use faster integer argument check
Browse files Browse the repository at this point in the history
PR-URL: #54089
  • Loading branch information
ronag committed Jul 29, 2024
1 parent 6ad25e3 commit d797180
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 @@ -28,6 +28,7 @@ const {
MathFloor,
MathMin,
MathTrunc,
NumberIsInteger,
NumberIsNaN,
NumberMAX_SAFE_INTEGER,
NumberMIN_SAFE_INTEGER,
Expand Down Expand Up @@ -208,23 +209,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(sourceStart) ? sourceStart : 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 d797180

Please sign in to comment.