Skip to content

Commit

Permalink
events: move slow path to separate function too
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
  • Loading branch information
mscdex authored and bnoordhuis committed Feb 11, 2015
1 parent 36a7795 commit 630f636
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,19 @@ function emitThree(handler, isFn, self, arg1, arg2, arg3) {
}
}

function emitMany(handler, isFn, self, args) {
if (isFn)
handler.apply(self, args);
else {
var len = handler.length;
var listeners = arrayClone(handler, len);
for (var i = 0; i < len; ++i)
listeners[i].apply(self, args);
}
}

EventEmitter.prototype.emit = function emit(type) {
var er, handler, len, args, i, listeners, events, domain;
var er, handler, len, args, i, events, domain;
var needDomainExit = false;

events = this._events;
Expand Down Expand Up @@ -160,14 +171,7 @@ EventEmitter.prototype.emit = function emit(type) {
args = new Array(len - 1);
for (i = 1; i < len; i++)
args[i - 1] = arguments[i];
if (isFn)
handler.apply(this, args);
else {
len = handler.length;
listeners = arrayClone(handler, len);
for (i = 0; i < len; ++i)
listeners[i].apply(this, args);
}
emitMany(handler, isFn, this, args);
}

if (needDomainExit)
Expand Down

0 comments on commit 630f636

Please sign in to comment.