Skip to content

Commit

Permalink
minimize triggerEvent code path when no listeners, r=tschaub (closes …
Browse files Browse the repository at this point in the history
…#2014)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9142 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
  • Loading branch information
Éric Lemoine committed Mar 28, 2009
1 parent 8bac392 commit cf5aa98
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions lib/OpenLayers/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<len; i++) {
var callback = listeners[i];
// bind the context to callback.obj
continueChain = callback.func.apply(callback.obj, [evt]);

if ((continueChain != undefined) && (continueChain == false)) {
// if callback returns false, execute no more callbacks.
break;
}
}
// don't fall through to other DOM elements
if (!this.fallThrough) {
OpenLayers.Event.stop(evt, true);
var listeners = listeners.slice(), continueChain;
for (var i=0, len=listeners.length; i<len; i++) {
var callback = listeners[i];
// bind the context to callback.obj
continueChain = callback.func.apply(callback.obj, [evt]);

if ((continueChain != undefined) && (continueChain == false)) {
// if callback returns false, execute no more callbacks.
break;
}
}
// don't fall through to other DOM elements
if (!this.fallThrough) {
OpenLayers.Event.stop(evt, true);
}
return continueChain;
},

Expand Down

0 comments on commit cf5aa98

Please sign in to comment.