Skip to content

Commit

Permalink
Optimize performance of Event.stopObserving by returning early when…
Browse files Browse the repository at this point in the history
… called on an element with no registered observers. [Victor Homyakov]
  • Loading branch information
savetheclocktower committed Aug 31, 2012
1 parent 29434fc commit ef4a928
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/prototype/dom/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -894,14 +894,17 @@
// for bulk removal of event listeners. We use them rather than recurse
// back into `stopObserving` to avoid touching the registry more often than
// necessary.

// Stop observing _all_ listeners on an element.
function stopObservingElement(element) {
var uid = getUniqueElementID(element),
registry = getRegistryForElement(element, uid);

// Do a manual registry lookup because we don't want to create a registry
// if one doesn't exist.
var uid = getUniqueElementID(element), registry = GLOBAL.Event.cache[uid];
// This way we can return early if there is no registry.
if (!registry) return;

destroyRegistryForElement(element, uid);

var entries, i;
for (var eventName in registry) {
// Explicitly skip elements so we don't accidentally find one with a
Expand Down

0 comments on commit ef4a928

Please sign in to comment.