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

Side by Side Diff: Source/core/css/SiblingTraversalStrategies.h

Issue 1096813005: Extending the NthIndexCache to support caching for the type of index. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Patch with new design Created 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | Source/core/dom/NthIndexCache.h » ('j') | Source/core/dom/NthIndexCache.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 int count = 0; 87 int count = 0;
88 for (const Element* sibling = ElementTraversal::previousSibling(element); si bling; sibling = ElementTraversal::previousSibling(*sibling)) 88 for (const Element* sibling = ElementTraversal::previousSibling(element); si bling; sibling = ElementTraversal::previousSibling(*sibling))
89 count++; 89 count++;
90 90
91 return count; 91 return count;
92 } 92 }
93 93
94 inline int DOMSiblingTraversalStrategy::countElementsOfTypeBefore(Element& eleme nt, const QualifiedName& type) const 94 inline int DOMSiblingTraversalStrategy::countElementsOfTypeBefore(Element& eleme nt, const QualifiedName& type) const
95 { 95 {
96 if (NthIndexCache* nthIndexCache = element.document().nthIndexCache())
97 return nthIndexCache->nthChildIndexOfType(element, type) - 1;
96 int count = 0; 98 int count = 0;
97 for (const Element* sibling = ElementTraversal::previousSibling(element, Has TagName(type)); sibling; sibling = ElementTraversal::previousSibling(*sibling, H asTagName(type))) 99 for (const Element* sibling = ElementTraversal::previousSibling(element, Has TagName(type)); sibling; sibling = ElementTraversal::previousSibling(*sibling, H asTagName(type)))
98 ++count; 100 ++count;
99 return count; 101 return count;
100 } 102 }
101 103
102 inline int DOMSiblingTraversalStrategy::countElementsAfter(Element& element) con st 104 inline int DOMSiblingTraversalStrategy::countElementsAfter(Element& element) con st
103 { 105 {
104 if (NthIndexCache* nthIndexCache = element.document().nthIndexCache()) 106 if (NthIndexCache* nthIndexCache = element.document().nthIndexCache())
105 return nthIndexCache->nthLastChildIndex(element) - 1; 107 return nthIndexCache->nthLastChildIndex(element) - 1;
106 108
107 int count = 0; 109 int count = 0;
108 for (const Element* sibling = ElementTraversal::nextSibling(element); siblin g; sibling = ElementTraversal::nextSibling(*sibling)) 110 for (const Element* sibling = ElementTraversal::nextSibling(element); siblin g; sibling = ElementTraversal::nextSibling(*sibling))
109 ++count; 111 ++count;
110 return count; 112 return count;
111 } 113 }
112 114
113 inline int DOMSiblingTraversalStrategy::countElementsOfTypeAfter(Element& elemen t, const QualifiedName& type) const 115 inline int DOMSiblingTraversalStrategy::countElementsOfTypeAfter(Element& elemen t, const QualifiedName& type) const
114 { 116 {
117 if (NthIndexCache* nthIndexCache = element.document().nthIndexCache())
118 return nthIndexCache->nthLastChildIndexOfType(element, type) - 1;
119
115 int count = 0; 120 int count = 0;
116 for (const Element* sibling = ElementTraversal::nextSibling(element, HasTagN ame(type)); sibling; sibling = ElementTraversal::nextSibling(*sibling, HasTagNam e(type))) 121 for (const Element* sibling = ElementTraversal::nextSibling(element, HasTagN ame(type)); sibling; sibling = ElementTraversal::nextSibling(*sibling, HasTagNam e(type)))
117 ++count; 122 ++count;
118 return count; 123 return count;
119 } 124 }
120 125
121 class ShadowDOMSiblingTraversalStrategy final { 126 class ShadowDOMSiblingTraversalStrategy final {
122 STACK_ALLOCATED(); 127 STACK_ALLOCATED();
123 public: 128 public:
124 ShadowDOMSiblingTraversalStrategy(const WillBeHeapVector<RawPtrWillBeMember< Node>, 32>& siblings, int nth) 129 ShadowDOMSiblingTraversalStrategy(const WillBeHeapVector<RawPtrWillBeMember< Node>, 32>& siblings, int nth)
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 if (m_siblings[i]->isElementNode() && toElement(m_siblings[i])->hasTagNa me(type)) 243 if (m_siblings[i]->isElementNode() && toElement(m_siblings[i])->hasTagNa me(type))
239 return ++count; 244 return ++count;
240 } 245 }
241 246
242 return count; 247 return count;
243 } 248 }
244 249
245 } 250 }
246 251
247 #endif 252 #endif
OLDNEW
« no previous file with comments | « no previous file | Source/core/dom/NthIndexCache.h » ('j') | Source/core/dom/NthIndexCache.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698