Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
event: improve performance of EventEmitter.emit
This restore some performance we lost when we introduced primordialias.
Improvements are up to +100%.
  • Loading branch information
mcollina committed Sep 20, 2019
commit c0989f4d081ded09b0677015c8271a4dcb7f4411
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