Skip to content
Permalink
Browse files

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: #26301
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
addaleax committed Feb 25, 2019
1 parent 9b4eec0 commit 5e4aa28e1cafee5d9210a9314cf64c7c0780410a
Showing with 2 additions and 6 deletions.
  1. +2 −6 lib/buffer.js
@@ -106,21 +106,17 @@ 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;
}
}

function createPool() {
poolSize = Buffer.poolSize;
allocPool = createUnsafeArrayBuffer(poolSize);
allocPool = createUnsafeBuffer(poolSize).buffer;
poolOffset = 0;
}
createPool();

0 comments on commit 5e4aa28

Please sign in to comment.
You can’t perform that action at this time.