From bed13444b13dc749d400160c4fbfa24e0f236723 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 7 Jul 2017 22:59:36 -0700 Subject: [PATCH] buffer: remove MAX_SAFE_INTEGER check on length MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MAX_SAFE_INTEGER is millions of times larger than the largest buffer allowed in Node.js. There is no need to squash the length down to MAX_SAFE_INTEGER. Removing that check results in a small but statistically significant increase for Buffer.from() operating on ArrayBuffers in some situations. PR-URL: https://github.com/nodejs/node/pull/14131 Reviewed-By: Luigi Pinca Reviewed-By: Refael Ackermann Reviewed-By: Colin Ihrig Reviewed-By: Tobias Nießen Reviewed-By: James M Snell Reviewed-By: Gibson Fahnestock --- lib/buffer.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/buffer.js b/lib/buffer.js index 5af10f5f30f6aa..babd63e06f03ba 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -353,8 +353,6 @@ function fromArrayBuffer(obj, byteOffset, length) { if (length !== length) { length = 0; } else if (length > 0) { - length = (length < Number.MAX_SAFE_INTEGER ? - length : Number.MAX_SAFE_INTEGER); if (length > maxLength) throw new RangeError("'length' is out of bounds"); } else {