Skip to content

Commit

Permalink
stream: pre-allocate _events
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Oct 27, 2023
1 parent 4ddb263 commit f3d826a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/internal/streams/duplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ function Duplex(options) {
if (!(this instanceof Duplex))
return new Duplex(options);

this._events = {
close: undefined,
error: undefined,
prefinish: undefined,
finish: undefined,
drain: undefined,
data: undefined,
end: undefined,
pause: undefined,
resume: undefined,
readable: undefined,
pipe: undefined,
unpipe: undefined,
};

this._readableState = new Readable.ReadableState(options, this, true);
this._writableState = new Writable.WritableState(options, this, true);

Expand Down
12 changes: 12 additions & 0 deletions lib/internal/streams/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,18 @@ function Readable(options) {
if (!(this instanceof Readable))
return new Readable(options);

this._events = {
close: undefined,
error: undefined,
data: undefined,
end: undefined,
pause: undefined,
resume: undefined,
readable: undefined,
pipe: undefined,
unpipe: undefined,
};

this._readableState = new ReadableState(options, this, false);

if (options) {
Expand Down
8 changes: 8 additions & 0 deletions lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ function Writable(options) {
if (!(this instanceof Writable))
return new Writable(options);

this._events = {

Check failure on line 385 in lib/internal/streams/writable.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 2 spaces but found 4
close: undefined,

Check failure on line 386 in lib/internal/streams/writable.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 4 spaces but found 6
error: undefined,

Check failure on line 387 in lib/internal/streams/writable.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 4 spaces but found 6
prefinish: undefined,

Check failure on line 388 in lib/internal/streams/writable.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 4 spaces but found 6
finish: undefined,

Check failure on line 389 in lib/internal/streams/writable.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 4 spaces but found 6
drain: undefined,

Check failure on line 390 in lib/internal/streams/writable.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 4 spaces but found 6
};

Check failure on line 391 in lib/internal/streams/writable.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 2 spaces but found 4

this._writableState = new WritableState(options, this, false);

if (options) {
Expand Down

0 comments on commit f3d826a

Please sign in to comment.