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

Side by Side Diff: third_party/WebKit/Source/core/css/invalidation/InvalidationSet.h

Issue 1580503004: CSS Invalidation: Avoid virtual functions in InvalidationSet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2564
Patch Set: Created 4 years, 11 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 | third_party/WebKit/Source/core/css/invalidation/InvalidationSet.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 enum InvalidationType { 49 enum InvalidationType {
50 InvalidateDescendants, 50 InvalidateDescendants,
51 InvalidateSiblings 51 InvalidateSiblings
52 }; 52 };
53 53
54 // Tracks data to determine which descendants in a DOM subtree, or 54 // Tracks data to determine which descendants in a DOM subtree, or
55 // siblings and their descendants, need to have style recalculated. 55 // siblings and their descendants, need to have style recalculated.
56 class CORE_EXPORT InvalidationSet : public RefCounted<InvalidationSet> { 56 class CORE_EXPORT InvalidationSet : public RefCounted<InvalidationSet> {
57 WTF_MAKE_NONCOPYABLE(InvalidationSet); 57 WTF_MAKE_NONCOPYABLE(InvalidationSet);
58 public: 58 public:
59 virtual ~InvalidationSet() {} 59 bool isDescendantInvalidationSet() const { return m_type == InvalidateDescen dants; }
60 60 bool isSiblingInvalidationSet() const { return m_type == InvalidateSiblings; }
61 virtual bool isDescendantInvalidationSet() const { return false; }
62 virtual bool isSiblingInvalidationSet() const { return false; }
63 61
64 static void cacheTracingFlag(); 62 static void cacheTracingFlag();
65 63
66 bool invalidatesElement(Element&) const; 64 bool invalidatesElement(Element&) const;
67 65
68 void addClass(const AtomicString& className); 66 void addClass(const AtomicString& className);
69 void addId(const AtomicString& id); 67 void addId(const AtomicString& id);
70 void addTagName(const AtomicString& tagName); 68 void addTagName(const AtomicString& tagName);
71 void addAttribute(const AtomicString& attributeLocalName); 69 void addAttribute(const AtomicString& attributeLocalName);
72 70
(...skipping 18 matching lines...) Expand all
91 89
92 #ifndef NDEBUG 90 #ifndef NDEBUG
93 void show() const; 91 void show() const;
94 #endif 92 #endif
95 93
96 const HashSet<AtomicString>& classSetForTesting() const { ASSERT(m_classes); return *m_classes; } 94 const HashSet<AtomicString>& classSetForTesting() const { ASSERT(m_classes); return *m_classes; }
97 const HashSet<AtomicString>& idSetForTesting() const { ASSERT(m_ids); return *m_ids; } 95 const HashSet<AtomicString>& idSetForTesting() const { ASSERT(m_ids); return *m_ids; }
98 const HashSet<AtomicString>& tagNameSetForTesting() const { ASSERT(m_tagName s); return *m_tagNames; } 96 const HashSet<AtomicString>& tagNameSetForTesting() const { ASSERT(m_tagName s); return *m_tagNames; }
99 const HashSet<AtomicString>& attributeSetForTesting() const { ASSERT(m_attri butes); return *m_attributes; } 97 const HashSet<AtomicString>& attributeSetForTesting() const { ASSERT(m_attri butes); return *m_attributes; }
100 98
99 void deref()
100 {
101 if (!derefBase())
102 return;
103 destroy();
104 }
105
101 protected: 106 protected:
102 InvalidationSet(); 107 InvalidationSet(InvalidationType);
103 108
104 void combine(const InvalidationSet& other); 109 void combine(const InvalidationSet& other);
105 110
106 private: 111 private:
112 void destroy();
113
107 HashSet<AtomicString>& ensureClassSet(); 114 HashSet<AtomicString>& ensureClassSet();
108 HashSet<AtomicString>& ensureIdSet(); 115 HashSet<AtomicString>& ensureIdSet();
109 HashSet<AtomicString>& ensureTagNameSet(); 116 HashSet<AtomicString>& ensureTagNameSet();
110 HashSet<AtomicString>& ensureAttributeSet(); 117 HashSet<AtomicString>& ensureAttributeSet();
111 118
112 // FIXME: optimize this if it becomes a memory issue. 119 // FIXME: optimize this if it becomes a memory issue.
113 OwnPtr<HashSet<AtomicString>> m_classes; 120 OwnPtr<HashSet<AtomicString>> m_classes;
114 OwnPtr<HashSet<AtomicString>> m_ids; 121 OwnPtr<HashSet<AtomicString>> m_ids;
115 OwnPtr<HashSet<AtomicString>> m_tagNames; 122 OwnPtr<HashSet<AtomicString>> m_tagNames;
116 OwnPtr<HashSet<AtomicString>> m_attributes; 123 OwnPtr<HashSet<AtomicString>> m_attributes;
117 124
125 unsigned m_type : 1;
126
118 // If true, all descendants might be invalidated, so a full subtree recalc i s required. 127 // If true, all descendants might be invalidated, so a full subtree recalc i s required.
119 unsigned m_allDescendantsMightBeInvalid : 1; 128 unsigned m_allDescendantsMightBeInvalid : 1;
120 129
121 // If true, the element itself is invalid. 130 // If true, the element itself is invalid.
122 unsigned m_invalidatesSelf : 1; 131 unsigned m_invalidatesSelf : 1;
123 132
124 // If true, all descendants which are custom pseudo elements must be invalid ated. 133 // If true, all descendants which are custom pseudo elements must be invalid ated.
125 unsigned m_customPseudoInvalid : 1; 134 unsigned m_customPseudoInvalid : 1;
126 135
127 // If true, the invalidation must traverse into ShadowRoots with this set. 136 // If true, the invalidation must traverse into ShadowRoots with this set.
128 unsigned m_treeBoundaryCrossing : 1; 137 unsigned m_treeBoundaryCrossing : 1;
129 138
130 // If true, insertion point descendants must be invalidated. 139 // If true, insertion point descendants must be invalidated.
131 unsigned m_insertionPointCrossing : 1; 140 unsigned m_insertionPointCrossing : 1;
132 }; 141 };
133 142
134 class CORE_EXPORT DescendantInvalidationSet final : public InvalidationSet { 143 class CORE_EXPORT DescendantInvalidationSet final : public InvalidationSet {
135 public: 144 public:
136 static PassRefPtr<DescendantInvalidationSet> create() 145 static PassRefPtr<DescendantInvalidationSet> create()
137 { 146 {
138 return adoptRef(new DescendantInvalidationSet); 147 return adoptRef(new DescendantInvalidationSet);
139 } 148 }
140 149
141 bool isDescendantInvalidationSet() const final { return true; }
142
143 void combine(const DescendantInvalidationSet& other) 150 void combine(const DescendantInvalidationSet& other)
144 { 151 {
145 InvalidationSet::combine(other); 152 InvalidationSet::combine(other);
146 } 153 }
147 154
148 private: 155 private:
149 DescendantInvalidationSet() {} 156 DescendantInvalidationSet()
157 : InvalidationSet(InvalidateDescendants) {}
150 }; 158 };
151 159
152 class CORE_EXPORT SiblingInvalidationSet final : public InvalidationSet { 160 class CORE_EXPORT SiblingInvalidationSet final : public InvalidationSet {
153 public: 161 public:
154 static PassRefPtr<SiblingInvalidationSet> create() 162 static PassRefPtr<SiblingInvalidationSet> create()
155 { 163 {
156 return adoptRef(new SiblingInvalidationSet); 164 return adoptRef(new SiblingInvalidationSet);
157 } 165 }
158 166
159 bool isSiblingInvalidationSet() const final { return true; }
160
161 void combine(const SiblingInvalidationSet& other); 167 void combine(const SiblingInvalidationSet& other);
162 168
163 DescendantInvalidationSet& descendants() { return *m_descendantInvalidationS et; } 169 DescendantInvalidationSet& descendants() { return *m_descendantInvalidationS et; }
164 const DescendantInvalidationSet& descendants() const { return *m_descendantI nvalidationSet; } 170 const DescendantInvalidationSet& descendants() const { return *m_descendantI nvalidationSet; }
165 171
166 unsigned maxDirectAdjacentSelectors() const { return m_maxDirectAdjacentSele ctors; } 172 unsigned maxDirectAdjacentSelectors() const { return m_maxDirectAdjacentSele ctors; }
167 void updateMaxDirectAdjacentSelectors(unsigned value) { m_maxDirectAdjacentS electors = std::max(value, m_maxDirectAdjacentSelectors); } 173 void updateMaxDirectAdjacentSelectors(unsigned value) { m_maxDirectAdjacentS electors = std::max(value, m_maxDirectAdjacentSelectors); }
168 174
169 private: 175 private:
170 SiblingInvalidationSet(); 176 SiblingInvalidationSet();
(...skipping 11 matching lines...) Expand all
182 InvalidationSetVector descendants; 188 InvalidationSetVector descendants;
183 InvalidationSetVector siblings; 189 InvalidationSetVector siblings;
184 }; 190 };
185 191
186 DEFINE_TYPE_CASTS(DescendantInvalidationSet, InvalidationSet, value, value->isDe scendantInvalidationSet(), value.isDescendantInvalidationSet()); 192 DEFINE_TYPE_CASTS(DescendantInvalidationSet, InvalidationSet, value, value->isDe scendantInvalidationSet(), value.isDescendantInvalidationSet());
187 DEFINE_TYPE_CASTS(SiblingInvalidationSet, InvalidationSet, value, value->isSibli ngInvalidationSet(), value.isSiblingInvalidationSet()); 193 DEFINE_TYPE_CASTS(SiblingInvalidationSet, InvalidationSet, value, value->isSibli ngInvalidationSet(), value.isSiblingInvalidationSet());
188 194
189 } // namespace blink 195 } // namespace blink
190 196
191 #endif // InvalidationSet_h 197 #endif // InvalidationSet_h
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/css/invalidation/InvalidationSet.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698