Skip to content

Commit

Permalink
buffer: avoid materializing ArrayBuffer for creation
Browse files Browse the repository at this point in the history
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 Mar 1, 2019
1 parent 9b4eec0 commit 5e4aa28
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5e4aa28

Please sign in to comment.