Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(593)

Unified Diff: Source/core/html/HTMLCollection.h

Issue 159503003: Do not cause unnecessary node lists invalidation on id/name attribute change (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/html/HTMLCollection.h
diff --git a/Source/core/html/HTMLCollection.h b/Source/core/html/HTMLCollection.h
index 2ec859c64978d0041a4d42cdf864778c4b180385..29f039efbd01f4cc974ee14e7a91174b1aabb954 100644
--- a/Source/core/html/HTMLCollection.h
+++ b/Source/core/html/HTMLCollection.h
@@ -41,7 +41,7 @@ public:
static PassRefPtr<HTMLCollection> create(ContainerNode* base, CollectionType);
virtual ~HTMLCollection();
- virtual void invalidateCache() const OVERRIDE;
+ virtual void invalidateCache(Document* oldDocument = 0) const OVERRIDE;
// DOM API
unsigned length() const { return m_collectionIndexCache.nodeCount(*this); }
@@ -69,9 +69,14 @@ protected:
bool shouldOnlyIncludeDirectChildren() const { return m_shouldOnlyIncludeDirectChildren; }
virtual void supportedPropertyNames(Vector<String>& names);
- virtual void updateNameCache() const;
- bool hasNameCache() const { return m_isNameCacheValid; }
Inactive 2014/02/12 18:26:08 Just a naming update to make it clear that: - the
- void setHasNameCache() const { m_isNameCacheValid = true; }
+ virtual void updateIdNameCache() const;
+ bool hasValidIdNameCache() const { return m_hasValidIdNameCache; }
+ void setHasValidIdNameCache() const
+ {
+ ASSERT(!m_hasValidIdNameCache);
+ m_hasValidIdNameCache = true;
+ document().incrementNodeListWithIdNameCacheCount();
+ }
typedef HashMap<StringImpl*, OwnPtr<Vector<Element*> > > NodeCacheMap;
Vector<Element*>* idCache(const AtomicString& name) const { return m_idCache.get(name.impl()); }
@@ -83,16 +88,30 @@ private:
Element* traverseNextElement(Element& previous, const ContainerNode& root) const;
static void append(NodeCacheMap&, const AtomicString&, Element*);
- void invalidateIdNameCacheMaps() const
+ void invalidateIdNameCacheMaps(Document* oldDocument = 0) const
{
+ if (!m_hasValidIdNameCache)
+ return;
+
+ // Make sure we decrement the NodeListWithIdNameCache count from
+ // the old document instead of the new one in the case the collection
+ // is moved to a new document.
+ unregisterIdNameCacheFromDocument(oldDocument ? *oldDocument : document());
+
m_idCache.clear();
m_nameCache.clear();
- m_isNameCacheValid = false;
+ m_hasValidIdNameCache = false;
+ }
+
+ void unregisterIdNameCacheFromDocument(Document& document) const
+ {
+ ASSERT(m_hasValidIdNameCache);
+ document.decrementNodeListWithIdNameCacheCount();
}
const unsigned m_overridesItemAfter : 1;
const unsigned m_shouldOnlyIncludeDirectChildren : 1;
- mutable unsigned m_isNameCacheValid : 1;
+ mutable unsigned m_hasValidIdNameCache : 1;
mutable NodeCacheMap m_idCache;
mutable NodeCacheMap m_nameCache;
mutable CollectionIndexCache<HTMLCollection, Element> m_collectionIndexCache;

Powered by Google App Engine
This is Rietveld 408576698