Skip to content

Commit

Permalink
buffer: remove MAX_SAFE_INTEGER check on length
Browse files Browse the repository at this point in the history
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: #14131
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
  • Loading branch information
Trott authored and Fishrock123 committed Jul 19, 2017
1 parent 07a5b15 commit 14dbecb
Showing 1 changed file with 0 additions and 2 deletions.
2 changes: 0 additions & 2 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 14dbecb

Please sign in to comment.