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; |
} |