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

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

Issue 224303004: Stop passing the root node to node lists traversal functions (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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/dom/LiveNodeListBase.h ('k') | Source/core/html/HTMLCollection.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/CollectionIndexCache.h
diff --git a/Source/core/html/CollectionIndexCache.h b/Source/core/html/CollectionIndexCache.h
index 4efcebb37d843f1c505432f7fb0a91a89bb56226..475e3285bb24063c311ad07e27b077a2c96877cf 100644
--- a/Source/core/html/CollectionIndexCache.h
+++ b/Source/core/html/CollectionIndexCache.h
@@ -64,8 +64,8 @@ public:
void invalidate();
private:
- NodeType* nodeBeforeCachedNode(const Collection&, unsigned index, const ContainerNode& root);
- NodeType* nodeAfterCachedNode(const Collection&, unsigned index, const ContainerNode& root);
+ NodeType* nodeBeforeCachedNode(const Collection&, unsigned index);
+ NodeType* nodeAfterCachedNode(const Collection&, unsigned index);
ALWAYS_INLINE NodeType* cachedNode() const { return m_currentNode; }
ALWAYS_INLINE unsigned cachedNodeIndex() const { ASSERT(cachedNode()); return m_cachedNodeIndex; }
@@ -124,29 +124,28 @@ inline NodeType* CollectionIndexCache<Collection, NodeType>::nodeAt(const Collec
if (isCachedNodeCountValid() && index >= cachedNodeCount())
return 0;
- ContainerNode& root = collection.rootNode();
if (cachedNode()) {
if (index > cachedNodeIndex())
- return nodeAfterCachedNode(collection, index, root);
+ return nodeAfterCachedNode(collection, index);
if (index < cachedNodeIndex())
- return nodeBeforeCachedNode(collection, index, root);
+ return nodeBeforeCachedNode(collection, index);
return cachedNode();
}
// No valid cache yet, let's find the first matching element.
ASSERT(!isCachedNodeCountValid());
- NodeType* firstNode = collection.traverseToFirstElement(root);
+ NodeType* firstNode = collection.traverseToFirstElement();
if (!firstNode) {
// The collection is empty.
setCachedNodeCount(0);
return 0;
}
setCachedNode(firstNode, 0);
- return index ? nodeAfterCachedNode(collection, index, root) : firstNode;
+ return index ? nodeAfterCachedNode(collection, index) : firstNode;
}
template <typename Collection, typename NodeType>
-inline NodeType* CollectionIndexCache<Collection, NodeType>::nodeBeforeCachedNode(const Collection& collection, unsigned index, const ContainerNode& root)
+inline NodeType* CollectionIndexCache<Collection, NodeType>::nodeBeforeCachedNode(const Collection& collection, unsigned index)
{
ASSERT(cachedNode()); // Cache should be valid.
unsigned currentIndex = cachedNodeIndex();
@@ -155,10 +154,10 @@ inline NodeType* CollectionIndexCache<Collection, NodeType>::nodeBeforeCachedNod
// Determine if we should traverse from the beginning of the collection instead of the cached node.
bool firstIsCloser = index < currentIndex - index;
if (firstIsCloser || !collection.canTraverseBackward()) {
- NodeType* firstNode = collection.traverseToFirstElement(root);
+ NodeType* firstNode = collection.traverseToFirstElement();
ASSERT(firstNode);
setCachedNode(firstNode, 0);
- return index ? nodeAfterCachedNode(collection, index, root) : firstNode;
+ return index ? nodeAfterCachedNode(collection, index) : firstNode;
}
// Backward traversal from the cached node to the requested index.
@@ -177,7 +176,7 @@ inline NodeType* CollectionIndexCache<Collection, NodeType>::nodeBeforeCachedNod
}
template <typename Collection, typename NodeType>
-inline NodeType* CollectionIndexCache<Collection, NodeType>::nodeAfterCachedNode(const Collection& collection, unsigned index, const ContainerNode& root)
+inline NodeType* CollectionIndexCache<Collection, NodeType>::nodeAfterCachedNode(const Collection& collection, unsigned index)
{
ASSERT(cachedNode()); // Cache should be valid.
unsigned currentIndex = cachedNodeIndex();
@@ -190,12 +189,12 @@ inline NodeType* CollectionIndexCache<Collection, NodeType>::nodeAfterCachedNode
ASSERT(lastItem);
setCachedNode(lastItem, cachedNodeCount() - 1);
if (index < cachedNodeCount() - 1)
- return nodeBeforeCachedNode(collection, index, root);
+ return nodeBeforeCachedNode(collection, index);
return lastItem;
}
// Forward traversal from the cached node to the requested index.
- NodeType* currentNode = collection.traverseForwardToOffset(index, *cachedNode(), currentIndex, root);
+ NodeType* currentNode = collection.traverseForwardToOffset(index, *cachedNode(), currentIndex);
if (!currentNode) {
// Did not find the node. On plus side, we now know the length.
setCachedNodeCount(currentIndex + 1);
« no previous file with comments | « Source/core/dom/LiveNodeListBase.h ('k') | Source/core/html/HTMLCollection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698