Skip to content

Commit f3d826a

Browse files
committed
stream: pre-allocate _events
1 parent 4ddb263 commit f3d826a

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

lib/internal/streams/duplex.js

+15
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ function Duplex(options) {
6363
if (!(this instanceof Duplex))
6464
return new Duplex(options);
6565

66+
this._events = {
67+
close: undefined,
68+
error: undefined,
69+
prefinish: undefined,
70+
finish: undefined,
71+
drain: undefined,
72+
data: undefined,
73+
end: undefined,
74+
pause: undefined,
75+
resume: undefined,
76+
readable: undefined,
77+
pipe: undefined,
78+
unpipe: undefined,
79+
};
80+
6681
this._readableState = new Readable.ReadableState(options, this, true);
6782
this._writableState = new Writable.WritableState(options, this, true);
6883

lib/internal/streams/readable.js

+12
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,18 @@ function Readable(options) {
316316
if (!(this instanceof Readable))
317317
return new Readable(options);
318318

319+
this._events = {
320+
close: undefined,
321+
error: undefined,
322+
data: undefined,
323+
end: undefined,
324+
pause: undefined,
325+
resume: undefined,
326+
readable: undefined,
327+
pipe: undefined,
328+
unpipe: undefined,
329+
};
330+
319331
this._readableState = new ReadableState(options, this, false);
320332

321333
if (options) {

lib/internal/streams/writable.js

+8
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,14 @@ function Writable(options) {
382382
if (!(this instanceof Writable))
383383
return new Writable(options);
384384

385+
this._events = {
386+
close: undefined,
387+
error: undefined,
388+
prefinish: undefined,
389+
finish: undefined,
390+
drain: undefined,
391+
};
392+
385393
this._writableState = new WritableState(options, this, false);
386394

387395
if (options) {

0 commit comments

Comments
 (0)