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

Unified Diff: Source/core/css/SiblingTraversalStrategies.h

Issue 1023393002: Cache element indices for :nth-child and :nth-last-child selectors. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Moved nth-index-cache scope to updateStyle Created 5 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
Index: Source/core/css/SiblingTraversalStrategies.h
diff --git a/Source/core/css/SiblingTraversalStrategies.h b/Source/core/css/SiblingTraversalStrategies.h
index f648cb9ef84f47a17bd54a0287e3f3988ce6dd16..e532bcfaaae28f9e89274806f9503e677e2788fb 100644
--- a/Source/core/css/SiblingTraversalStrategies.h
+++ b/Source/core/css/SiblingTraversalStrategies.h
@@ -29,8 +29,10 @@
#ifndef SiblingTraversalStrategies_h
#define SiblingTraversalStrategies_h
+#include "core/dom/Document.h"
#include "core/dom/Element.h"
#include "core/dom/ElementTraversal.h"
+#include "core/dom/NthIndexCache.h"
#include "core/layout/style/LayoutStyle.h"
namespace blink {
@@ -79,6 +81,9 @@ inline bool DOMSiblingTraversalStrategy::isLastOfType(Element& element, const Qu
inline int DOMSiblingTraversalStrategy::countElementsBefore(Element& element) const
{
+ if (element.document().nthIndexCache())
+ return element.document().nthIndexCache()->nthChildIndex(element) - 1;
+
int count = 0;
for (const Element* sibling = ElementTraversal::previousSibling(element); sibling; sibling = ElementTraversal::previousSibling(*sibling))
count++;
@@ -96,6 +101,9 @@ inline int DOMSiblingTraversalStrategy::countElementsOfTypeBefore(Element& eleme
inline int DOMSiblingTraversalStrategy::countElementsAfter(Element& element) const
{
+ if (element.document().nthIndexCache())
+ return element.document().nthIndexCache()->nthLastChildIndex(element) - 1;
+
int count = 0;
for (const Element* sibling = ElementTraversal::nextSibling(element); sibling; sibling = ElementTraversal::nextSibling(*sibling))
++count;

Powered by Google App Engine
This is Rietveld 408576698