From edd7c579e82b5343577c4306b537b94b71612394 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Fri, 20 Sep 2019 19:06:20 +0200 Subject: [PATCH] events: improve performance of EventEmitter.emit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This restore some performance we lost when we introduced primordialias. Improvements are up to +100%. PR-URL: https://github.com/nodejs/node/pull/29633 Reviewed-By: Michaƫl Zasso Reviewed-By: Anna Henningsen Reviewed-By: David Carlier Reviewed-By: Luigi Pinca Reviewed-By: Trivikram Kamat Reviewed-By: Colin Ihrig Reviewed-By: Yongsheng Zhang Reviewed-By: Ruben Bridgewater --- lib/events.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/events.js b/lib/events.js index f6e4996d20b40f..1356806f6544c3 100644 --- a/lib/events.js +++ b/lib/events.js @@ -22,6 +22,7 @@ 'use strict'; const { Math, Object, Reflect } = primordials; +const apply = Reflect.apply; var spliceOne; @@ -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;