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.
  • Loading branch information
addaleax committed Feb 25, 2019
1 parent 250dce3 commit 6b86059
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 @@ -105,21 +105,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 6b86059

Please sign in to comment.