From 5e4aa28e1cafee5d9210a9314cf64c7c0780410a Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Mon, 25 Feb 2019 04:41:53 +0100 Subject: [PATCH] buffer: avoid materializing ArrayBuffer for creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: James M Snell --- lib/buffer.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/buffer.js b/lib/buffer.js index 1d98b26d0d49ba..c4b7e3165b8ae5 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -106,13 +106,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; } @@ -120,7 +116,7 @@ function createUnsafeArrayBuffer(size) { function createPool() { poolSize = Buffer.poolSize; - allocPool = createUnsafeArrayBuffer(poolSize); + allocPool = createUnsafeBuffer(poolSize).buffer; poolOffset = 0; } createPool();