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

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

Issue 67473002: Have ElementTraversal / NodeTraversal's next() methods take a reference (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase on master Created 7 years, 1 month 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/HTMLDialogElement.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 a6faa8660ea52e106b8731df266c309be3f248c6..b6e97846a2b1925cb0561d7564a40462ce690d61 100644
--- a/Source/core/html/HTMLCollection.cpp
+++ b/Source/core/html/HTMLCollection.cpp
@@ -306,26 +306,28 @@ inline Element* firstMatchingElement(const NodeListType* nodeList, ContainerNode
{
Element* element = ElementTraversal::firstWithin(root);
while (element && !isMatchingElement(nodeList, element))
- element = ElementTraversal::next(element, root);
+ element = ElementTraversal::next(*element, root);
return element;
}
template <class NodeListType>
-inline Element* nextMatchingElement(const NodeListType* nodeList, Element* current, ContainerNode* root)
+inline Element* nextMatchingElement(const NodeListType* nodeList, Element& current, ContainerNode* root)
{
+ Element* next = &current;
do {
- current = ElementTraversal::next(current, root);
- } while (current && !isMatchingElement(nodeList, current));
- return current;
+ next = ElementTraversal::next(*next, root);
+ } while (next && !isMatchingElement(nodeList, next));
+ return next;
}
template <class NodeListType>
-inline Element* traverseMatchingElementsForwardToOffset(const NodeListType* nodeList, unsigned offset, Element* currentElement, unsigned& currentOffset, ContainerNode* root)
+inline Element* traverseMatchingElementsForwardToOffset(const NodeListType* nodeList, unsigned offset, Element& currentElement, unsigned& currentOffset, ContainerNode* root)
{
ASSERT(currentOffset < offset);
- while ((currentElement = nextMatchingElement(nodeList, currentElement, root))) {
+ Element* next = &currentElement;
+ while ((next = nextMatchingElement(nodeList, *next, root))) {
if (++currentOffset == offset)
- return currentElement;
+ return next;
}
return 0;
}
@@ -355,7 +357,7 @@ inline Element* LiveNodeListBase::traverseLiveNodeListFirstElement(ContainerNode
}
// FIXME: This should be in LiveNodeList
-inline Element* LiveNodeListBase::traverseLiveNodeListForwardToOffset(unsigned offset, Element* currentElement, unsigned& currentOffset, ContainerNode* root) const
+inline Element* LiveNodeListBase::traverseLiveNodeListForwardToOffset(unsigned offset, Element& currentElement, unsigned& currentOffset, ContainerNode* root) const
{
ASSERT(isNodeList(type()));
ASSERT(type() != ChildNodeListType);
@@ -476,9 +478,9 @@ inline Node* LiveNodeListBase::itemBeforeOrAfterCachedItem(unsigned offset, Cont
if (type() == ChildNodeListType)
currentItem = traverseChildNodeListForwardToOffset(offset, currentItem, currentOffset);
else if (isNodeList(type()))
- currentItem = traverseLiveNodeListForwardToOffset(offset, toElement(currentItem), currentOffset, root);
+ currentItem = traverseLiveNodeListForwardToOffset(offset, toElement(*currentItem), currentOffset, root);
else
- currentItem = static_cast<const HTMLCollection*>(this)->traverseForwardToOffset(offset, toElement(currentItem), currentOffset, offsetInArray, root);
+ currentItem = static_cast<const HTMLCollection*>(this)->traverseForwardToOffset(offset, toElement(*currentItem), currentOffset, offsetInArray, root);
if (!currentItem) {
// Did not find the item. On plus side, we now know the length.
@@ -549,31 +551,33 @@ inline Element* HTMLCollection::traverseFirstElement(unsigned& offsetInArray, Co
return firstMatchingElement(static_cast<const HTMLCollection*>(this), root);
}
-inline Element* HTMLCollection::traverseNextElement(unsigned& offsetInArray, Element* previous, ContainerNode* root) const
+inline Element* HTMLCollection::traverseNextElement(unsigned& offsetInArray, Element& previous, ContainerNode* root) const
{
if (overridesItemAfter())
- return virtualItemAfter(offsetInArray, previous);
+ return virtualItemAfter(offsetInArray, &previous);
ASSERT(!offsetInArray);
if (shouldOnlyIncludeDirectChildren())
- return nextMatchingChildElement(this, previous, root);
+ return nextMatchingChildElement(this, &previous, root);
return nextMatchingElement(this, previous, root);
}
-inline Element* HTMLCollection::traverseForwardToOffset(unsigned offset, Element* currentElement, unsigned& currentOffset, unsigned& offsetInArray, ContainerNode* root) const
+inline Element* HTMLCollection::traverseForwardToOffset(unsigned offset, Element& currentElement, unsigned& currentOffset, unsigned& offsetInArray, ContainerNode* root) const
{
ASSERT(currentOffset < offset);
if (overridesItemAfter()) {
offsetInArray = m_cachedElementsArrayOffset;
- while ((currentElement = virtualItemAfter(offsetInArray, currentElement))) {
+ Element* next = &currentElement;
+ while ((next = virtualItemAfter(offsetInArray, next))) {
if (++currentOffset == offset)
- return currentElement;
+ return next;
}
return 0;
}
if (shouldOnlyIncludeDirectChildren()) {
- while ((currentElement = nextMatchingChildElement(this, currentElement, root))) {
+ Element* next = &currentElement;
+ while ((next = nextMatchingChildElement(this, next, root))) {
if (++currentOffset == offset)
- return currentElement;
+ return next;
}
return 0;
}
@@ -594,7 +598,7 @@ Node* HTMLCollection::namedItem(const AtomicString& name) const
unsigned arrayOffset = 0;
unsigned i = 0;
- for (Element* element = traverseFirstElement(arrayOffset, root); element; element = traverseNextElement(arrayOffset, element, root)) {
+ for (Element* element = traverseFirstElement(arrayOffset, root); element; element = traverseNextElement(arrayOffset, *element, root)) {
if (checkForNameMatch(element, /* checkName */ false, name)) {
setItemCache(element, i, arrayOffset);
return element;
@@ -603,7 +607,7 @@ Node* HTMLCollection::namedItem(const AtomicString& name) const
}
i = 0;
- for (Element* element = traverseFirstElement(arrayOffset, root); element; element = traverseNextElement(arrayOffset, element, root)) {
+ for (Element* element = traverseFirstElement(arrayOffset, root); element; element = traverseNextElement(arrayOffset, *element, root)) {
if (checkForNameMatch(element, /* checkName */ true, name)) {
setItemCache(element, i, arrayOffset);
return element;
@@ -624,7 +628,7 @@ void HTMLCollection::updateNameCache() const
return;
unsigned arrayOffset = 0;
- for (Element* element = traverseFirstElement(arrayOffset, root); element; element = traverseNextElement(arrayOffset, element, root)) {
+ for (Element* element = traverseFirstElement(arrayOffset, root); element; element = traverseNextElement(arrayOffset, *element, root)) {
const AtomicString& idAttrVal = element->getIdAttribute();
if (!idAttrVal.isEmpty())
appendIdCache(idAttrVal, element);
« no previous file with comments | « Source/core/html/HTMLCollection.h ('k') | Source/core/html/HTMLDialogElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698