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
This commit is contained in:
Éric Lemoine
2009-03-28 16:17:54 +00:00
parent 8bac39243f
commit cf5aa98cce
+7 -5
View File
@@ -693,6 +693,12 @@ OpenLayers.Events = OpenLayers.Class({
* chain of listeners will stop getting called. * chain of listeners will stop getting called.
*/ */
triggerEvent: function (type, evt) { triggerEvent: function (type, evt) {
var listeners = this.listeners[type];
// fast path
if(!listeners || listeners.length == 0) {
return;
}
// prep evt object with object & div references // prep evt object with object & div references
if (evt == null) { if (evt == null) {
@@ -707,10 +713,7 @@ OpenLayers.Events = OpenLayers.Class({
// execute all callbacks registered for specified type // execute all callbacks registered for specified type
// get a clone of the listeners array to // get a clone of the listeners array to
// allow for splicing during callbacks // allow for splicing during callbacks
var listeners = (this.listeners[type]) ? var listeners = listeners.slice(), continueChain;
this.listeners[type].slice() : null;
if ((listeners != null) && (listeners.length > 0)) {
var continueChain;
for (var i=0, len=listeners.length; i<len; i++) { for (var i=0, len=listeners.length; i<len; i++) {
var callback = listeners[i]; var callback = listeners[i];
// bind the context to callback.obj // bind the context to callback.obj
@@ -725,7 +728,6 @@ OpenLayers.Events = OpenLayers.Class({
if (!this.fallThrough) { if (!this.fallThrough) {
OpenLayers.Event.stop(evt, true); OpenLayers.Event.stop(evt, true);
} }
}
return continueChain; return continueChain;
}, },