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>
This commit is contained in:
Anna Henningsen committed 2019-03-01 21:58:06 +01:00
1 parent 31975bbc88
commit 6a0f4636d9
1 file changed
+2 -6
+2 -6
View File
@@ -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();