From cf5aa98ccecd477c57097e1cae5ddb1acd928ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Sat, 28 Mar 2009 16:17:54 +0000 Subject: [PATCH] minimize triggerEvent code path when no listeners, r=tschaub (closes #2014) git-svn-id: http://svn.openlayers.org/trunk/openlayers@9142 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Events.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/OpenLayers/Events.js b/lib/OpenLayers/Events.js index f02c88670e..ab806f23f1 100644 --- a/lib/OpenLayers/Events.js +++ b/lib/OpenLayers/Events.js @@ -693,6 +693,12 @@ OpenLayers.Events = OpenLayers.Class({ * chain of listeners will stop getting called. */ triggerEvent: function (type, evt) { + var listeners = this.listeners[type]; + + // fast path + if(!listeners || listeners.length == 0) { + return; + } // prep evt object with object & div references if (evt == null) { @@ -707,25 +713,21 @@ OpenLayers.Events = OpenLayers.Class({ // execute all callbacks registered for specified type // get a clone of the listeners array to // allow for splicing during callbacks - var listeners = (this.listeners[type]) ? - this.listeners[type].slice() : null; - if ((listeners != null) && (listeners.length > 0)) { - var continueChain; - for (var i=0, len=listeners.length; i