Skip to content

Loading…

Performance optimization in stopObservingElement() #62

Closed
wants to merge 1 commit into from

2 participants

@victor-homyakov
  1. Do not call getRegistryForElement() because it unnecessarily creates registry for each element
  2. Short-circuit when registry not exists
@victor-homyakov victor-homyakov Performance optimization in stopObservingElement()
1. Do not call getRegistryForElement() because it unnecessarily creates registry for each element
2. Short-circuit when registry not exists
334993d
@savetheclocktower
Collaborator

Applied in ef4a928. I'm keeping the destroyRegistryForElement function for now, even though it's called in only one place, but I might change my mind later on. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 28, 2012
  1. @victor-homyakov

    Performance optimization in stopObservingElement()

    victor-homyakov committed
    1. Do not call getRegistryForElement() because it unnecessarily creates registry for each element
    2. Short-circuit when registry not exists
Showing with 8 additions and 11 deletions.
  1. +8 −11 src/prototype/dom/event.js
View
19 src/prototype/dom/event.js
@@ -543,12 +543,6 @@
return CACHE[uid];
}
- function destroyRegistryForElement(element, uid) {
- if (Object.isUndefined(uid))
- uid = getUniqueElementID(element);
- delete GLOBAL.Event.cache[uid];
- }
-
// The `register` and `unregister` functions handle creating the responder
// and managing an event registry. They _don't_ attach and detach the
// listeners themselves.
@@ -900,11 +894,14 @@
// Stop observing _all_ listeners on an element.
function stopObservingElement(element) {
- var uid = getUniqueElementID(element),
- registry = getRegistryForElement(element, uid);
-
- destroyRegistryForElement(element, uid);
-
+ var CACHE = GLOBAL.Event.cache, uid = getUniqueElementID(element);
+ // do not create registry if it not exists - don't call getRegistryForElement()
+ var registry = CACHE[uid];
+ // do nothing if registry not exists
+ if (!registry) return;
+
+ delete CACHE[uid];
+
var entries, i;
for (var eventName in registry) {
// Explicitly skip elements so we don't accidentally find one with a
Something went wrong with that request. Please try again.