Chromium Code Reviews| 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) |