Skip to content

Commit 3012d31

Browse files
ronagtargos
authored andcommittedOct 2, 2024
buffer: use faster integer argument check
PR-URL: #54089 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daniel Lemire <daniel@lemire.me> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 329be5c commit 3012d31

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed
 

‎lib/buffer.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const {
2828
MathFloor,
2929
MathMin,
3030
MathTrunc,
31+
NumberIsInteger,
3132
NumberIsNaN,
3233
NumberMAX_SAFE_INTEGER,
3334
NumberMIN_SAFE_INTEGER,
@@ -208,23 +209,23 @@ function _copy(source, target, targetStart, sourceStart, sourceEnd) {
208209
if (targetStart === undefined) {
209210
targetStart = 0;
210211
} else {
211-
targetStart = toInteger(targetStart, 0);
212+
targetStart = NumberIsInteger(targetStart) ? targetStart : toInteger(targetStart, 0);
212213
if (targetStart < 0)
213214
throw new ERR_OUT_OF_RANGE('targetStart', '>= 0', targetStart);
214215
}
215216

216217
if (sourceStart === undefined) {
217218
sourceStart = 0;
218219
} else {
219-
sourceStart = toInteger(sourceStart, 0);
220+
sourceStart = NumberIsInteger(sourceStart) ? sourceStart : toInteger(sourceStart, 0);
220221
if (sourceStart < 0 || sourceStart > source.length)
221222
throw new ERR_OUT_OF_RANGE('sourceStart', `>= 0 && <= ${source.length}`, sourceStart);
222223
}
223224

224225
if (sourceEnd === undefined) {
225226
sourceEnd = source.length;
226227
} else {
227-
sourceEnd = toInteger(sourceEnd, 0);
228+
sourceEnd = NumberIsInteger(sourceEnd) ? sourceEnd : toInteger(sourceEnd, 0);
228229
if (sourceEnd < 0)
229230
throw new ERR_OUT_OF_RANGE('sourceEnd', '>= 0', sourceEnd);
230231
}

0 commit comments

Comments
 (0)
Please sign in to comment.