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

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

Issue 215073003: Move HTMLCollection's id / name cache to a new NamedItemCache class (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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.cpp » ('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 0b0bce0f17c357f35fab2f810a247c70944d8676..153d8ffe6f3af11a6ad0bf124dfeae5fffc95cac 100644
--- a/Source/core/html/HTMLCollection.cpp
+++ b/Source/core/html/HTMLCollection.cpp
@@ -162,7 +162,6 @@ HTMLCollection::HTMLCollection(ContainerNode& ownerNode, CollectionType type, It
: LiveNodeListBase(ownerNode, rootTypeFromCollectionType(type), invalidationTypeExcludingIdAndNameAttributes(type), type)
, m_overridesItemAfter(itemAfterOverrideType == OverridesItemAfter)
, m_shouldOnlyIncludeDirectChildren(shouldTypeOnlyIncludeDirectChildren(type))
- , m_hasValidIdNameCache(false)
{
ScriptWrappable::init(this);
}
@@ -387,11 +386,12 @@ Element* HTMLCollection::namedItem(const AtomicString& name) const
// that are allowed a name attribute.
updateIdNameCache();
- Vector<Element*>* idResults = idCache(name);
+ const NamedItemCache& cache = namedItemCache();
+ Vector<Element*>* idResults = cache.getElementsById(name);
if (idResults && !idResults->isEmpty())
return idResults->first();
- Vector<Element*>* nameResults = nameCache(name);
+ Vector<Element*>* nameResults = cache.getElementsByName(name);
if (nameResults && !nameResults->isEmpty())
return nameResults->first();
@@ -443,19 +443,18 @@ void HTMLCollection::updateIdNameCache() const
if (hasValidIdNameCache())
return;
+ NamedItemCache& cache = createNamedItemCache();
ContainerNode& root = rootNode();
for (Element* element = traverseToFirstElement(root); element; element = traverseNextElement(*element, root)) {
const AtomicString& idAttrVal = element->getIdAttribute();
if (!idAttrVal.isEmpty())
- appendIdCache(idAttrVal, element);
+ cache.addElementWithId(idAttrVal, element);
if (!element->isHTMLElement())
continue;
const AtomicString& nameAttrVal = element->getNameAttribute();
if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && (type() != DocAll || nameShouldBeVisibleInDocumentAll(toHTMLElement(*element))))
- appendNameCache(nameAttrVal, element);
+ cache.addElementWithName(nameAttrVal, element);
}
-
- setHasValidIdNameCache();
}
void HTMLCollection::namedItems(const AtomicString& name, Vector<RefPtr<Element> >& result) const
@@ -466,8 +465,9 @@ void HTMLCollection::namedItems(const AtomicString& name, Vector<RefPtr<Element>
updateIdNameCache();
- Vector<Element*>* idResults = idCache(name);
- Vector<Element*>* nameResults = nameCache(name);
+ const NamedItemCache& cache = namedItemCache();
+ Vector<Element*>* idResults = cache.getElementsById(name);
+ Vector<Element*>* nameResults = cache.getElementsByName(name);
for (unsigned i = 0; idResults && i < idResults->size(); ++i)
result.append(idResults->at(i));
@@ -476,12 +476,4 @@ void HTMLCollection::namedItems(const AtomicString& name, Vector<RefPtr<Element>
result.append(nameResults->at(i));
}
-void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element* element)
-{
- OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).storedValue->value;
- if (!vector)
- vector = adoptPtr(new Vector<Element*>);
- vector->append(element);
-}
-
} // namespace WebCore
« no previous file with comments | « Source/core/html/HTMLCollection.h ('k') | Source/core/html/HTMLFormControlsCollection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698