Skip to content

Commit

Permalink
events: improve performance of EventEmitter.emit
Browse files Browse the repository at this point in the history
This restore some performance we lost when we introduced primordialias.
Improvements are up to +100%.

PR-URL: #29633
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
mcollina authored and BridgeAR committed Sep 25, 2019
1 parent 68630c5 commit 0a47d06
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'use strict';

const { Math, Object, Reflect } = primordials;
const apply = Reflect.apply;

var spliceOne;

Expand Down Expand Up @@ -206,12 +207,12 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
return false;

if (typeof handler === 'function') {
Reflect.apply(handler, this, args);
apply(handler, this, args);
} else {
const len = handler.length;
const listeners = arrayClone(handler, len);
for (var i = 0; i < len; ++i)
Reflect.apply(listeners[i], this, args);
apply(listeners[i], this, args);
}

return true;
Expand Down

0 comments on commit 0a47d06

Please sign in to comment.