mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
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:
1 file changed
+2
-6
+2
-6
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user