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

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

Issue 108343008: Move traverseLiveNodeListFirstElement() to LiveNodeList class (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 11 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 3c8e3e439675c191a3c88568853eb476e531dd75..dffff6c04baeee534d368500ac71236ee1989447 100644
--- a/Source/core/html/HTMLCollection.cpp
+++ b/Source/core/html/HTMLCollection.cpp
@@ -353,16 +353,21 @@ static inline Node* traverseSiblingsForwardToOffset(unsigned offset, Node& curre
return 0;
}
-// FIXME: This should be in LiveNodeList
-inline Element* LiveNodeListBase::traverseLiveNodeListFirstElement(ContainerNode& root) const
+// FIXME: This should be in LiveNodeList.cpp but it needs to stay here until firstMatchingElement()
+// and others are moved to a separate header.
+inline Node* LiveNodeList::traverseToFirstElement(ContainerNode& root) const
{
ASSERT(isLiveNodeListType(type()));
- ASSERT(type() != ChildNodeListType);
- if (type() == HTMLTagNodeListType)
+ switch (type()) {
+ case ChildNodeListType:
+ return root.firstChild();
+ case HTMLTagNodeListType:
return firstMatchingElement(static_cast<const HTMLTagNodeList*>(this), root);
- if (type() == ClassNodeListType)
+ case ClassNodeListType:
return firstMatchingElement(static_cast<const ClassNodeList*>(this), root);
- return firstMatchingElement(static_cast<const LiveNodeList*>(this), root);
+ default:
+ return firstMatchingElement(static_cast<const LiveNodeList*>(this), root);
+ }
}
// FIXME: This should be in LiveNodeList.cpp but it needs to stay here until traverseMatchingElementsForwardToOffset()
@@ -434,12 +439,10 @@ Node* LiveNodeListBase::item(unsigned offset) const
setItemCache(lastItem, cachedLength() - 1);
} else if (!isItemCacheValid() || isFirstItemCloserThanCachedItem(offset) || (overridesItemAfter() && offset < cachedItemOffset())) {
Node* firstItem;
- if (type() == ChildNodeListType)
- firstItem = root->firstChild();
- else if (isLiveNodeListType(type()))
- firstItem = traverseLiveNodeListFirstElement(*root);
+ if (isLiveNodeListType(type()))
+ firstItem = static_cast<const LiveNodeList*>(this)->traverseToFirstElement(*root);
else
- firstItem = static_cast<const HTMLCollection*>(this)->traverseFirstElement(*root);
+ firstItem = static_cast<const HTMLCollection*>(this)->traverseToFirstElement(*root);
if (!firstItem) {
setLengthCache(0);
@@ -541,7 +544,7 @@ inline Element* nextMatchingChildElement(const HTMLCollection* nodeList, Element
return next;
}
-inline Element* HTMLCollection::traverseFirstElement(ContainerNode& root) const
+inline Element* HTMLCollection::traverseToFirstElement(ContainerNode& root) const
{
if (overridesItemAfter())
return virtualItemAfter(0);
@@ -594,7 +597,7 @@ Node* HTMLCollection::namedItem(const AtomicString& name) const
return 0;
unsigned i = 0;
- for (Element* element = traverseFirstElement(*root); element; element = traverseNextElement(*element, root)) {
+ for (Element* element = traverseToFirstElement(*root); element; element = traverseNextElement(*element, root)) {
if (checkForNameMatch(element, /* checkName */ false, name)) {
setItemCache(element, i);
return element;
@@ -603,7 +606,7 @@ Node* HTMLCollection::namedItem(const AtomicString& name) const
}
i = 0;
- for (Element* element = traverseFirstElement(*root); element; element = traverseNextElement(*element, root)) {
+ for (Element* element = traverseToFirstElement(*root); element; element = traverseNextElement(*element, root)) {
if (checkForNameMatch(element, /* checkName */ true, name)) {
setItemCache(element, i);
return element;
@@ -623,7 +626,7 @@ void HTMLCollection::updateNameCache() const
if (!root)
return;
- for (Element* element = traverseFirstElement(*root); element; element = traverseNextElement(*element, root)) {
+ for (Element* element = traverseToFirstElement(*root); element; element = traverseNextElement(*element, root)) {
const AtomicString& idAttrVal = element->getIdAttribute();
if (!idAttrVal.isEmpty())
appendIdCache(idAttrVal, element);
« 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