Skip to content

Commit 630f636

Browse files
mscdexbnoordhuis
authored andcommitted
events: move slow path to separate function too
This keeps in line with how things are done for the fast path and *might* even provide a *slight* performance increase. PR-URL: #785 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Evan Lucas <evanlucas@me.com>
1 parent 36a7795 commit 630f636

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lib/events.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,19 @@ function emitThree(handler, isFn, self, arg1, arg2, arg3) {
101101
}
102102
}
103103

104+
function emitMany(handler, isFn, self, args) {
105+
if (isFn)
106+
handler.apply(self, args);
107+
else {
108+
var len = handler.length;
109+
var listeners = arrayClone(handler, len);
110+
for (var i = 0; i < len; ++i)
111+
listeners[i].apply(self, args);
112+
}
113+
}
114+
104115
EventEmitter.prototype.emit = function emit(type) {
105-
var er, handler, len, args, i, listeners, events, domain;
116+
var er, handler, len, args, i, events, domain;
106117
var needDomainExit = false;
107118

108119
events = this._events;
@@ -160,14 +171,7 @@ EventEmitter.prototype.emit = function emit(type) {
160171
args = new Array(len - 1);
161172
for (i = 1; i < len; i++)
162173
args[i - 1] = arguments[i];
163-
if (isFn)
164-
handler.apply(this, args);
165-
else {
166-
len = handler.length;
167-
listeners = arrayClone(handler, len);
168-
for (i = 0; i < len; ++i)
169-
listeners[i].apply(this, args);
170-
}
174+
emitMany(handler, isFn, this, args);
171175
}
172176

173177
if (needDomainExit)

0 commit comments

Comments
 (0)