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

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

Issue 154183002: Update HTMLCollection.namedItem() to use the id/name cache (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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') | no next file » | 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 4d2fbc0fea46e920e95ed2ce9a19118196f81a9a..5062a0da018cfbcd3621452c1b15876d9244a8f4 100644
--- a/Source/core/html/HTMLCollection.cpp
+++ b/Source/core/html/HTMLCollection.cpp
@@ -414,21 +414,6 @@ static inline bool nameShouldBeVisibleInDocumentAll(const HTMLElement& element)
|| element.hasLocalName(selectTag);
}
-bool HTMLCollection::checkForNameMatch(const Element& element, bool checkName, const AtomicString& name) const
-{
- if (!element.isHTMLElement())
- return false;
-
- const HTMLElement& e = toHTMLElement(element);
- if (!checkName)
- return e.getIdAttribute() == name;
-
- if (type() == DocAll && !nameShouldBeVisibleInDocumentAll(e))
- return false;
-
- return e.getNameAttribute() == name && e.getIdAttribute() != name;
-}
-
inline Element* firstMatchingChildElement(const HTMLCollection& nodeList, const ContainerNode& root)
{
Element* element = ElementTraversal::firstWithin(root);
@@ -493,25 +478,15 @@ 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();
- ContainerNode& root = rootNode();
- unsigned i = 0;
- for (Element* element = traverseToFirstElement(root); element; element = traverseNextElement(*element, root)) {
- if (checkForNameMatch(*element, /* checkName */ false, name)) {
- m_collectionIndexCache.setCachedNode(element, i);
- return element;
- }
- i++;
- }
+ Vector<Element*>* idResults = idCache(name);
+ if (idResults && !idResults->isEmpty())
+ return idResults->first();
- i = 0;
- for (Element* element = traverseToFirstElement(root); element; element = traverseNextElement(*element, root)) {
- if (checkForNameMatch(*element, /* checkName */ true, name)) {
- m_collectionIndexCache.setCachedNode(element, i);
- return element;
- }
- i++;
- }
+ Vector<Element*>* nameResults = nameCache(name);
+ if (nameResults && !nameResults->isEmpty())
+ return nameResults->first();
return 0;
}
« no previous file with comments | « Source/core/html/HTMLCollection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698