Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,13 @@ Buffer.copyBytesFrom = function copyBytesFrom(view, offset, length) {

const viewLength = TypedArrayPrototypeGetLength(view);
if (viewLength === 0) {
return Buffer.alloc(0);
return new FastBuffer();
}

if (offset !== undefined || length !== undefined) {
if (offset !== undefined) {
validateInteger(offset, 'offset', 0);
if (offset >= viewLength) return Buffer.alloc(0);
if (offset >= viewLength) return new FastBuffer();
} else {
offset = 0;
}
Expand Down Expand Up @@ -1261,7 +1261,7 @@ if (internalBinding('config').hasIntl) {
throw new ERR_INVALID_ARG_TYPE('source',
['Buffer', 'Uint8Array'], source);
}
if (source.length === 0) return Buffer.alloc(0);
if (source.length === 0) return new FastBuffer();

fromEncoding = normalizeEncoding(fromEncoding) || fromEncoding;
toEncoding = normalizeEncoding(toEncoding) || toEncoding;
Expand Down
3 changes: 2 additions & 1 deletion lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const {
defaultTriggerAsyncIdScope,
symbols: { async_id_symbol, owner_symbol },
} = require('internal/async_hooks');
const { FastBuffer } = require('internal/buffer');
const { UV_UDP_REUSEADDR } = internalBinding('constants').os;

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

if (list.length === 0)
ArrayPrototypePush(list, Buffer.alloc(0));
ArrayPrototypePush(list, new FastBuffer());

// If the socket hasn't been bound yet, push the outbound packet onto the
// send queue and send after binding is complete.
Expand Down
5 changes: 3 additions & 2 deletions lib/internal/debugger/inspect_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const { ERR_DEBUGGER_ERROR } = require('internal/errors').codes;
const { EventEmitter } = require('events');
const http = require('http');
const { URL } = require('internal/url');
const { FastBuffer } = require('internal/buffer');

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

Expand Down Expand Up @@ -79,7 +80,7 @@ function encodeFrameHybi17(payload) {
additionalLength[0] = (dataLength & 0xFF00) >> 8;
additionalLength[1] = dataLength & 0xFF;
} else {
additionalLength = Buffer.alloc(0);
additionalLength = new FastBuffer();
singleByteLength = dataLength;
}

Expand Down Expand Up @@ -233,7 +234,7 @@ class Client extends EventEmitter {
this._lastId = 0;
this._socket = null;
this._pending = {};
this._unprocessed = Buffer.alloc(0);
this._unprocessed = new FastBuffer();
}

callMethod(method, params) {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/streams/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,7 @@ function fromList(n, state) {
buf[idx++] = null;
}
} else if (len - idx === 0) {
ret = Buffer.alloc(0);
ret = new FastBuffer();
} else if (len - idx === 1) {
ret = buf[idx];
buf[idx++] = null;
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const {
kTestTimeoutFailure,
Test,
} = require('internal/test_runner/test');
const { FastBuffer } = require('internal/buffer');

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

while (bufferHead && headerIndex !== 0) {
const nonSerializedData = headerIndex === -1 ?
Expand Down
7 changes: 4 additions & 3 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const {
validateUint32,
validateFiniteNumber,
} = require('internal/validators');
const { FastBuffer } = require('internal/buffer');

const kFlushFlag = Symbol('kFlushFlag');
const kError = Symbol('kError');
Expand Down Expand Up @@ -150,7 +151,7 @@ function zlibBufferOnError(err) {
function zlibBufferOnEnd() {
let buf;
if (this.nread === 0) {
buf = Buffer.alloc(0);
buf = new FastBuffer();
} else {
const bufs = this.buffers;
buf = (bufs.length === 1 ? bufs[0] : Buffer.concat(bufs, this.nread));
Expand Down Expand Up @@ -301,7 +302,7 @@ ZlibBase.prototype.reset = function() {
* @returns {void}
*/
ZlibBase.prototype._flush = function(callback) {
this._transform(Buffer.alloc(0), '', callback);
this._transform(new FastBuffer(), '', callback);
};

/**
Expand Down Expand Up @@ -476,7 +477,7 @@ function processChunkSync(self, chunk, flushFlag) {
_close(self);

if (nread === 0)
return Buffer.alloc(0);
return new FastBuffer();

return (buffers.length === 1 ? buffers[0] : Buffer.concat(buffers, nread));
}
Expand Down
Loading