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

Unified Diff: Source/core/html/CollectionIndexCache.h

Issue 229213002: Make HTMLCollection / NodeList backward traversal consistent with forward one (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 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
Index: Source/core/html/CollectionIndexCache.h
diff --git a/Source/core/html/CollectionIndexCache.h b/Source/core/html/CollectionIndexCache.h
index 475e3285bb24063c311ad07e27b077a2c96877cf..9898de0cf274d2cf10c7f3d6098b805ff29f8afe 100644
--- a/Source/core/html/CollectionIndexCache.h
+++ b/Source/core/html/CollectionIndexCache.h
@@ -161,18 +161,11 @@ inline NodeType* CollectionIndexCache<Collection, NodeType>::nodeBeforeCachedNod
}
// Backward traversal from the cached node to the requested index.
- NodeType* currentNode = cachedNode();
ASSERT(collection.canTraverseBackward());
- while ((currentNode = collection.itemBefore(currentNode))) {
- ASSERT(currentIndex);
- --currentIndex;
- if (currentIndex == index) {
- setCachedNode(currentNode, currentIndex);
- return currentNode;
- }
- }
- ASSERT_NOT_REACHED();
- return 0;
+ NodeType* currentNode = collection.traverseBackwardToOffset(index, *cachedNode(), currentIndex);
Inactive 2014/04/09 23:08:58 We now pass a reference instead of a pointer to th
+ ASSERT(currentNode);
+ setCachedNode(currentNode, currentIndex);
+ return currentNode;
}
template <typename Collection, typename NodeType>
@@ -185,7 +178,7 @@ inline NodeType* CollectionIndexCache<Collection, NodeType>::nodeAfterCachedNode
// Determine if we should traverse from the end of the collection instead of the cached node.
bool lastIsCloser = isCachedNodeCountValid() && cachedNodeCount() - index < index - currentIndex;
if (lastIsCloser && collection.canTraverseBackward()) {
- NodeType* lastItem = collection.itemBefore(0);
Inactive 2014/04/09 23:08:58 We now call traverseToLastElement() here instead o
+ NodeType* lastItem = collection.traverseToLastElement();
ASSERT(lastItem);
setCachedNode(lastItem, cachedNodeCount() - 1);
if (index < cachedNodeCount() - 1)

Powered by Google App Engine
This is Rietveld 408576698