lib: use `FastBuffer` for empty buffer allocation · nodejs/node@1a0c3dd · GitHub
Skip to content

Commit 1a0c3dd

Browse files
gurgundayRafaelGSS
authored andcommitted
lib: use FastBuffer for empty buffer allocation
PR-URL: #60558 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
1 parent d90001a commit 1a0c3dd

6 files changed

Lines changed: 15 additions & 11 deletions

File tree

lib/buffer.js

Lines changed: 3 additions & 3 deletions

lib/dgram.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const {
7373
defaultTriggerAsyncIdScope,
7474
symbols: { async_id_symbol, owner_symbol },
7575
} = require('internal/async_hooks');
76+
const { FastBuffer } = require('internal/buffer');
7677
const { UV_UDP_REUSEADDR } = internalBinding('constants').os;
7778

7879
const {
@@ -688,7 +689,7 @@ Socket.prototype.send = function(buffer,
688689
this.bind({ port: 0, exclusive: true }, null);
689690

690691
if (list.length === 0)
691-
ArrayPrototypePush(list, Buffer.alloc(0));
692+
ArrayPrototypePush(list, new FastBuffer());
692693

693694
// If the socket hasn't been bound yet, push the outbound packet onto the
694695
// send queue and send after binding is complete.

lib/internal/debugger/inspect_client.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const { ERR_DEBUGGER_ERROR } = require('internal/errors').codes;
1616
const { EventEmitter, once } = require('events');
1717
const http = require('http');
1818
const { URL } = require('internal/url');
19+
const { FastBuffer } = require('internal/buffer');
1920

2021
const debuglog = require('internal/util/debuglog').debuglog('inspect');
2122

@@ -79,7 +80,7 @@ function encodeFrameHybi17(payload) {
7980
additionalLength[0] = (dataLength & 0xFF00) >> 8;
8081
additionalLength[1] = dataLength & 0xFF;
8182
} else {
82-
additionalLength = Buffer.alloc(0);
83+
additionalLength = new FastBuffer();
8384
singleByteLength = dataLength;
8485
}
8586

@@ -233,7 +234,7 @@ class Client extends EventEmitter {
233234
this._lastId = 0;
234235
this._socket = null;
235236
this._pending = {};
236-
this._unprocessed = Buffer.alloc(0);
237+
this._unprocessed = new FastBuffer();
237238
}
238239

239240
callMethod(method, params) {

lib/internal/streams/readable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ function fromList(n, state) {
16051605
buf[idx++] = null;
16061606
}
16071607
} else if (len - idx === 0) {
1608-
ret = Buffer.alloc(0);
1608+
ret = new FastBuffer();
16091609
} else if (len - idx === 1) {
16101610
ret = buf[idx];
16111611
buf[idx++] = null;

lib/internal/test_runner/runner.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const {
7878
kTestTimeoutFailure,
7979
Test,
8080
} = require('internal/test_runner/test');
81+
const { FastBuffer } = require('internal/buffer');
8182

8283
const {
8384
convertStringToRegExp,
@@ -324,7 +325,7 @@ class FileTest extends Test {
324325
// This method is called when it is known that there is at least one message
325326
let bufferHead = this.#rawBuffer[0];
326327
let headerIndex = bufferHead.indexOf(v8Header);
327-
let nonSerialized = Buffer.alloc(0);
328+
let nonSerialized = new FastBuffer();
328329

329330
while (bufferHead && headerIndex !== 0) {
330331
const nonSerializedData = headerIndex === -1 ?

lib/zlib.js

Lines changed: 4 additions & 3 deletions

0 commit comments

Comments
 (0)