From e6e6b07e512dd4e71b0458cb02901ce6d5398e29 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 cfe3080810..f8d615ee0c 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -354,8 +354,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 {