From 8dcd6dccab9dad5f599a22331aeb447f15b588c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herbert=20Voj=C4=8D=C3=ADk?= Date: Thu, 16 Sep 2010 13:08:09 +0200 Subject: [PATCH] Common subexpression in emit. --- lib/events.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/events.js b/lib/events.js index a6923b149e3..d41608deee9 100644 --- a/lib/events.js +++ b/lib/events.js @@ -18,27 +18,25 @@ EventEmitter.prototype.emit = function (type) { } if (!this._events) return false; - if (!this._events[type]) return false; + var handler = this._events[type]; + if (!handler) return false; - if (typeof this._events[type] == 'function') { + if (typeof handler == 'function') { if (arguments.length <= 3) { // fast case - this._events[type].call( this - , arguments[1] - , arguments[2] - ); + handler.call(this, arguments[1], arguments[2]); } else { // slower var args = Array.prototype.slice.call(arguments, 1); - this._events[type].apply(this, args); + handler.apply(this, args); } return true; - } else if (isArray(this._events[type])) { + } else if (isArray(handler)) { var args = Array.prototype.slice.call(arguments, 1); - var listeners = this._events[type].slice(0); + var listeners = handler.slice(); for (var i = 0, l = listeners.length; i < l; i++) { listeners[i].apply(this, args); }