diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-02-25 04:41:53 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-03-01 21:58:06 +0100 |
commit | 6a0f4636d9f8e94ebe905f0807edd0f5d9fbdd51 (patch) | |
tree | 22c500043f1ff290fabff6cbf2fa6a820123d596 /lib/buffer.js | |
parent | 31975bbc88d353cf2eecc93c9d2cde62dba67b2c (diff) | |
download | node-new-6a0f4636d9f8e94ebe905f0807edd0f5d9fbdd51.tar.gz |
buffer: avoid materializing ArrayBuffer for creation
Do not create an `ArrayBuffer` if the engine’s settings avoid it
and we don’t need it.
PR-URL: https://github.com/nodejs/node/pull/26301
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/buffer.js')
-rw-r--r-- | lib/buffer.js | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/lib/buffer.js b/lib/buffer.js index 8b7aba1aaf..9684eaa6ba 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -105,13 +105,9 @@ let poolSize, poolOffset, allocPool; const zeroFill = bindingZeroFill || [0]; function createUnsafeBuffer(size) { - return new FastBuffer(createUnsafeArrayBuffer(size)); -} - -function createUnsafeArrayBuffer(size) { zeroFill[0] = 0; try { - return new ArrayBuffer(size); + return new FastBuffer(size); } finally { zeroFill[0] = 1; } @@ -119,7 +115,7 @@ function createUnsafeArrayBuffer(size) { function createPool() { poolSize = Buffer.poolSize; - allocPool = createUnsafeArrayBuffer(poolSize); + allocPool = createUnsafeBuffer(poolSize).buffer; poolOffset = 0; } createPool(); |