mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
buffer: use faster integer argument check
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
f9f9a421a8
commit
e7edcf38cd
1 changed files with 4 additions and 3 deletions
|
@ -28,6 +28,7 @@ const {
|
|||
MathFloor,
|
||||
MathMin,
|
||||
MathTrunc,
|
||||
NumberIsInteger,
|
||||
NumberIsNaN,
|
||||
NumberMAX_SAFE_INTEGER,
|
||||
NumberMIN_SAFE_INTEGER,
|
||||
|
@ -208,7 +209,7 @@ 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);
|
||||
}
|
||||
|
@ -216,7 +217,7 @@ function _copy(source, target, targetStart, sourceStart, sourceEnd) {
|
|||
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);
|
||||
}
|
||||
|
@ -224,7 +225,7 @@ function _copy(source, target, targetStart, sourceStart, sourceEnd) {
|
|||
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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue