Permalink
Browse files

buffer: remove MAX_SAFE_INTEGER check on length

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 <luigipinca@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
  • Loading branch information...
Trott committed Jul 8, 2017
1 parent 80c9fd9 commit e6e6b07e512dd4e71b0458cb02901ce6d5398e29
Showing with 0 additions and 2 deletions.
  1. +0 −2 lib/buffer.js
View
@@ -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 {

0 comments on commit e6e6b07

Please sign in to comment.