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

Unified Diff: third_party/WebKit/Source/core/dom/NthIndexCache.h

Issue 1655993005: Only cache nth-indices when child count > 32. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed constant Created 4 years, 10 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: third_party/WebKit/Source/core/dom/NthIndexCache.h
diff --git a/third_party/WebKit/Source/core/dom/NthIndexCache.h b/third_party/WebKit/Source/core/dom/NthIndexCache.h
index 074994be8063a673984acf822174161e2e566979..5ae0d46e250292a01a19105de6b57fcef06870ee 100644
--- a/third_party/WebKit/Source/core/dom/NthIndexCache.h
+++ b/third_party/WebKit/Source/core/dom/NthIndexCache.h
@@ -21,17 +21,15 @@ class CORE_EXPORT NthIndexData final : public NoBaseWillBeGarbageCollected<NthIn
WTF_MAKE_NONCOPYABLE(NthIndexData);
DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(NthIndexData);
public:
- NthIndexData() { }
+ NthIndexData(ContainerNode&);
+ NthIndexData(ContainerNode&, const QualifiedName& type);
- unsigned nthIndex(Element&);
- unsigned nthIndexOfType(Element&, const QualifiedName&);
- unsigned nthLastIndex(Element&);
- unsigned nthLastIndexOfType(Element&, const QualifiedName&);
+ unsigned nthIndex(Element&) const;
+ unsigned nthLastIndex(Element&) const;
+ unsigned nthOfTypeIndex(Element&) const;
+ unsigned nthLastOfTypeIndex(Element&) const;
private:
- unsigned cacheNthIndices(Element&);
- unsigned cacheNthIndicesOfType(Element&, const QualifiedName&);
-
WillBeHeapHashMap<RawPtrWillBeMember<Element>, unsigned> m_elementIndexMap;
unsigned m_count = 0;
@@ -45,38 +43,20 @@ public:
explicit NthIndexCache(Document&);
~NthIndexCache();
- unsigned nthChildIndex(Element& element)
- {
- ASSERT(element.parentNode());
- return ensureNthIndexDataFor(*element.parentNode()).nthIndex(element);
- }
-
- unsigned nthChildIndexOfType(Element& element, const QualifiedName& type)
- {
- ASSERT(element.parentNode());
- return nthIndexDataWithTagName(element).nthIndexOfType(element, type);
- }
-
- unsigned nthLastChildIndex(Element& element)
- {
- ASSERT(element.parentNode());
- return ensureNthIndexDataFor(*element.parentNode()).nthLastIndex(element);
- }
-
- unsigned nthLastChildIndexOfType(Element& element, const QualifiedName& type)
- {
- ASSERT(element.parentNode());
- return nthIndexDataWithTagName(element).nthLastIndexOfType(element, type);
- }
+ static unsigned nthChildIndex(Element&);
+ static unsigned nthLastChildIndex(Element&);
+ static unsigned nthOfTypeIndex(Element&);
+ static unsigned nthLastOfTypeIndex(Element&);
private:
using IndexByType = WillBeHeapHashMap<String, OwnPtrWillBeMember<NthIndexData>>;
using ParentMap = WillBeHeapHashMap<RefPtrWillBeMember<Node>, OwnPtrWillBeMember<NthIndexData>>;
using ParentMapForType = WillBeHeapHashMap<RefPtrWillBeMember<Node>, OwnPtrWillBeMember<IndexByType>>;
- NthIndexData& ensureNthIndexDataFor(Node&);
- IndexByType& ensureTypeIndexMap(Node&);
- NthIndexData& nthIndexDataWithTagName(Element&);
+ void cacheNthIndexDataForParent(Element&);
+ void cacheNthOfTypeIndexDataForParent(Element&);
+ IndexByType& ensureTypeIndexMap(ContainerNode&);
+ NthIndexData* nthTypeIndexDataForParent(Element&) const;
RawPtrWillBeMember<Document> m_document;
OwnPtrWillBeMember<ParentMap> m_parentMap;
« no previous file with comments | « third_party/WebKit/Source/core/css/SelectorChecker.cpp ('k') | third_party/WebKit/Source/core/dom/NthIndexCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698