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

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

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
« no previous file with comments | « Source/core/html/HTMLCollection.h ('k') | Source/core/html/HTMLFormControlsCollection.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLCollection.cpp
diff --git a/Source/core/html/HTMLCollection.cpp b/Source/core/html/HTMLCollection.cpp
index a6f239f4b794d5517814a2a9f530e3e66de1a3a2..0fb783f8e1b09e08709d0a351fc340bc8f116d0f 100644
--- a/Source/core/html/HTMLCollection.cpp
+++ b/Source/core/html/HTMLCollection.cpp
@@ -164,7 +164,7 @@ HTMLCollection::HTMLCollection(ContainerNode* ownerNode, CollectionType type, It
: LiveNodeListBase(ownerNode, rootTypeFromCollectionType(type), invalidationTypeExcludingIdAndNameAttributes(type), type)
, m_overridesItemAfter(itemAfterOverrideType == OverridesItemAfter)
, m_shouldOnlyIncludeDirectChildren(shouldTypeOnlyIncludeDirectChildren(type))
- , m_isNameCacheValid(false)
+ , m_hasValidIdNameCache(false)
{
ScriptWrappable::init(this);
}
@@ -176,6 +176,8 @@ PassRefPtr<HTMLCollection> HTMLCollection::create(ContainerNode* base, Collectio
HTMLCollection::~HTMLCollection()
{
+ if (hasValidIdNameCache())
+ unregisterIdNameCacheFromDocument(document());
// HTMLNameCollection, ClassCollection and TagCollection remove cache by themselves.
if (type() != WindowNamedItems && type() != DocumentNamedItems && type() != ClassCollectionType
&& type() != HTMLTagCollectionType && type() != TagCollectionType) {
@@ -183,10 +185,10 @@ HTMLCollection::~HTMLCollection()
}
}
-void HTMLCollection::invalidateCache() const
+void HTMLCollection::invalidateCache(Document* oldDocument) const
{
m_collectionIndexCache.invalidate();
- invalidateIdNameCacheMaps();
+ invalidateIdNameCacheMaps(oldDocument);
}
template <class NodeListType>
@@ -476,7 +478,7 @@ Element* HTMLCollection::namedItem(const AtomicString& name) const
// attribute. If a match is not found, the method then searches for an
// object with a matching name attribute, but only on those elements
// that are allowed a name attribute.
- updateNameCache();
+ updateIdNameCache();
Vector<Element*>* idResults = idCache(name);
if (idResults && !idResults->isEmpty())
@@ -529,9 +531,9 @@ void HTMLCollection::namedPropertyEnumerator(Vector<String>& names, ExceptionSta
supportedPropertyNames(names);
}
-void HTMLCollection::updateNameCache() const
+void HTMLCollection::updateIdNameCache() const
{
- if (hasNameCache())
+ if (hasValidIdNameCache())
return;
ContainerNode& root = rootNode();
@@ -546,7 +548,7 @@ void HTMLCollection::updateNameCache() const
appendNameCache(nameAttrVal, element);
}
- setHasNameCache();
+ setHasValidIdNameCache();
}
void HTMLCollection::namedItems(const AtomicString& name, Vector<RefPtr<Element> >& result) const
@@ -555,7 +557,7 @@ void HTMLCollection::namedItems(const AtomicString& name, Vector<RefPtr<Element>
if (name.isEmpty())
return;
- updateNameCache();
+ updateIdNameCache();
Vector<Element*>* idResults = idCache(name);
Vector<Element*>* nameResults = nameCache(name);
« no previous file with comments | « Source/core/html/HTMLCollection.h ('k') | Source/core/html/HTMLFormControlsCollection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698