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

Side by Side Diff: Source/core/dom/NthIndexCache.h

Issue 1108783002: Don't cache nth-indices of pseudo elements. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NthIndexCache_h 5 #ifndef NthIndexCache_h
6 #define NthIndexCache_h 6 #define NthIndexCache_h
7 7
8 #include "core/CoreExport.h" 8 #include "core/CoreExport.h"
9 #include "core/dom/Element.h" 9 #include "core/dom/Element.h"
10 #include "core/dom/ElementTraversal.h" 10 #include "core/dom/ElementTraversal.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 using ParentMap = WillBeHeapHashMap<RefPtrWillBeMember<Node>, OwnPtrWillBeMe mber<NthIndexData>>; 50 using ParentMap = WillBeHeapHashMap<RefPtrWillBeMember<Node>, OwnPtrWillBeMe mber<NthIndexData>>;
51 51
52 OwnPtrWillBeMember<ParentMap> m_parentMap; 52 OwnPtrWillBeMember<ParentMap> m_parentMap;
53 RawPtrWillBeMember<Document> m_document; 53 RawPtrWillBeMember<Document> m_document;
54 uint64_t m_domTreeVersion; 54 uint64_t m_domTreeVersion;
55 }; 55 };
56 56
57 inline unsigned NthIndexCache::NthIndexData::nthIndex(Element& element) 57 inline unsigned NthIndexCache::NthIndexData::nthIndex(Element& element)
58 { 58 {
59 if (!m_count) 59 if (!m_count && !element.isPseudoElement())
60 return cacheNthIndices(element); 60 return cacheNthIndices(element);
61 61
62 unsigned index = 0; 62 unsigned index = 0;
63 for (Element* sibling = &element; sibling; sibling = ElementTraversal::previ ousSibling(*sibling), index++) { 63 for (Element* sibling = &element; sibling; sibling = ElementTraversal::previ ousSibling(*sibling), index++) {
esprehn 2015/04/30 01:03:52 Why go through this loop for pseudo elements? I kn
64 auto it = m_elementIndexMap.find(sibling); 64 auto it = m_elementIndexMap.find(sibling);
65 if (it != m_elementIndexMap.end()) 65 if (it != m_elementIndexMap.end())
66 return it->value + index; 66 return it->value + index;
67 } 67 }
68 return index; 68 return index;
69 } 69 }
70 70
71 inline unsigned NthIndexCache::NthIndexData::nthLastIndex(Element& element) 71 inline unsigned NthIndexCache::NthIndexData::nthLastIndex(Element& element)
72 { 72 {
73 unsigned index = nthIndex(element); 73 unsigned index = nthIndex(element);
74 return m_count - index + 1; 74 return m_count - index + 1;
75 } 75 }
76 76
77 inline unsigned NthIndexCache::nthChildIndex(Element& element) 77 inline unsigned NthIndexCache::nthChildIndex(Element& element)
78 { 78 {
79 ASSERT(element.parentNode()); 79 ASSERT(element.parentNode());
80 return ensureNthIndexDataFor(*element.parentNode()).nthIndex(element); 80 return ensureNthIndexDataFor(*element.parentNode()).nthIndex(element);
81 } 81 }
82 82
83 inline unsigned NthIndexCache::nthLastChildIndex(Element& element) 83 inline unsigned NthIndexCache::nthLastChildIndex(Element& element)
84 { 84 {
85 ASSERT(element.parentNode()); 85 ASSERT(element.parentNode());
86 return ensureNthIndexDataFor(*element.parentNode()).nthLastIndex(element); 86 return ensureNthIndexDataFor(*element.parentNode()).nthLastIndex(element);
87 } 87 }
88 88
89 } // namespace blink 89 } // namespace blink
90 90
91 #endif // NthIndexCache_h 91 #endif // NthIndexCache_h
OLDNEW
« no previous file with comments | « LayoutTests/fast/css/nth-child-of-pseudo-element-assert-expected.txt ('k') | Source/core/dom/NthIndexCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698