From e7edcf38cd595ac36e9422da690cebae69528e7a Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Wed, 31 Jul 2024 00:29:51 +0200 Subject: [PATCH] buffer: use faster integer argument check PR-URL: https://github.com/nodejs/node/pull/54089 Reviewed-By: Yagiz Nizipli Reviewed-By: Matteo Collina Reviewed-By: Luigi Pinca Reviewed-By: Daniel Lemire Reviewed-By: James M Snell Reviewed-By: Benjamin Gruenbaum --- lib/buffer.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/buffer.js b/lib/buffer.js index 823a9249eccc52..e5bebbe592902e 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -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); }