| OLD | NEW |
| 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 18 matching lines...) Expand all Loading... |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef InvalidationSet_h | 31 #ifndef InvalidationSet_h |
| 32 #define InvalidationSet_h | 32 #define InvalidationSet_h |
| 33 | 33 |
| 34 #include "core/CoreExport.h" | 34 #include "core/CoreExport.h" |
| 35 #include "wtf/Allocator.h" | 35 #include "wtf/Allocator.h" |
| 36 #include "wtf/Assertions.h" | 36 #include "wtf/Assertions.h" |
| 37 #include "wtf/Forward.h" | 37 #include "wtf/Forward.h" |
| 38 #include "wtf/HashSet.h" | 38 #include "wtf/HashSet.h" |
| 39 #include "wtf/RefCounted.h" | |
| 40 #include "wtf/RefPtr.h" | 39 #include "wtf/RefPtr.h" |
| 41 #include "wtf/text/AtomicStringHash.h" | 40 #include "wtf/text/AtomicStringHash.h" |
| 42 #include "wtf/text/StringHash.h" | 41 #include "wtf/text/StringHash.h" |
| 43 #include <memory> | 42 #include <memory> |
| 44 | 43 |
| 45 namespace blink { | 44 namespace blink { |
| 46 | 45 |
| 47 class Element; | 46 class Element; |
| 48 class TracedValue; | 47 class TracedValue; |
| 49 | 48 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 71 // | 70 // |
| 72 // .v * {} | 71 // .v * {} |
| 73 // For class v we will have a DescendantInvalidationSet with wholeSubtreeInval
id. | 72 // For class v we will have a DescendantInvalidationSet with wholeSubtreeInval
id. |
| 74 // | 73 // |
| 75 // .u ~ * {} | 74 // .u ~ * {} |
| 76 // For class u we will have a SiblingInvalidationSet with wholeSubtreeInvalid
and invalidatesSelf (for all siblings, the sibling itself is invalidated). | 75 // For class u we will have a SiblingInvalidationSet with wholeSubtreeInvalid
and invalidatesSelf (for all siblings, the sibling itself is invalidated). |
| 77 // | 76 // |
| 78 // .t .v, .t ~ .z {} | 77 // .t .v, .t ~ .z {} |
| 79 // For class t we will have a SiblingInvalidationSet containing class z, with
the SiblingInvalidationSet also holding descendants containing class v. | 78 // For class t we will have a SiblingInvalidationSet containing class z, with
the SiblingInvalidationSet also holding descendants containing class v. |
| 80 // | 79 // |
| 81 class CORE_EXPORT InvalidationSet : public RefCounted<InvalidationSet> { | 80 // We avoid virtual functions to minimize space consumption. |
| 81 class CORE_EXPORT InvalidationSet { |
| 82 WTF_MAKE_NONCOPYABLE(InvalidationSet); | 82 WTF_MAKE_NONCOPYABLE(InvalidationSet); |
| 83 USING_FAST_MALLOC_WITH_TYPE_NAME(blink::InvalidationSet); | 83 USING_FAST_MALLOC_WITH_TYPE_NAME(blink::InvalidationSet); |
| 84 public: | 84 public: |
| 85 InvalidationType type() const { return static_cast<InvalidationType>(m_type)
; } | 85 InvalidationType type() const { return static_cast<InvalidationType>(m_type)
; } |
| 86 bool isDescendantInvalidationSet() const { return type() == InvalidateDescen
dants; } | 86 bool isDescendantInvalidationSet() const { return type() == InvalidateDescen
dants; } |
| 87 bool isSiblingInvalidationSet() const { return type() == InvalidateSiblings;
} | 87 bool isSiblingInvalidationSet() const { return type() == InvalidateSiblings;
} |
| 88 | 88 |
| 89 static void cacheTracingFlag(); | 89 static void cacheTracingFlag(); |
| 90 | 90 |
| 91 bool invalidatesElement(Element&) const; | 91 bool invalidatesElement(Element&) const; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 116 bool isEmpty() const { return !m_classes && !m_ids && !m_tagNames && !m_attr
ibutes && !m_customPseudoInvalid && !m_insertionPointCrossing && !m_invalidatesS
lotted; } | 116 bool isEmpty() const { return !m_classes && !m_ids && !m_tagNames && !m_attr
ibutes && !m_customPseudoInvalid && !m_insertionPointCrossing && !m_invalidatesS
lotted; } |
| 117 | 117 |
| 118 bool isAlive() const { return m_isAlive; } | 118 bool isAlive() const { return m_isAlive; } |
| 119 | 119 |
| 120 void toTracedValue(TracedValue*) const; | 120 void toTracedValue(TracedValue*) const; |
| 121 | 121 |
| 122 #ifndef NDEBUG | 122 #ifndef NDEBUG |
| 123 void show() const; | 123 void show() const; |
| 124 #endif | 124 #endif |
| 125 | 125 |
| 126 const HashSet<AtomicString>& classSetForTesting() const { ASSERT(m_classes);
return *m_classes; } | 126 const HashSet<AtomicString>& classSetForTesting() const { DCHECK(m_classes);
return *m_classes; } |
| 127 const HashSet<AtomicString>& idSetForTesting() const { ASSERT(m_ids); return
*m_ids; } | 127 const HashSet<AtomicString>& idSetForTesting() const { DCHECK(m_ids); return
*m_ids; } |
| 128 const HashSet<AtomicString>& tagNameSetForTesting() const { ASSERT(m_tagName
s); return *m_tagNames; } | 128 const HashSet<AtomicString>& tagNameSetForTesting() const { DCHECK(m_tagName
s); return *m_tagNames; } |
| 129 const HashSet<AtomicString>& attributeSetForTesting() const { ASSERT(m_attri
butes); return *m_attributes; } | 129 const HashSet<AtomicString>& attributeSetForTesting() const { DCHECK(m_attri
butes); return *m_attributes; } |
| 130 | 130 |
| 131 void ref() { ++m_refCount; } |
| 131 void deref() | 132 void deref() |
| 132 { | 133 { |
| 133 if (!derefBase()) | 134 DCHECK_GT(m_refCount, 0); |
| 134 return; | 135 --m_refCount; |
| 135 destroy(); | 136 if (!m_refCount) |
| 137 destroy(); |
| 136 } | 138 } |
| 137 | 139 |
| 138 void combine(const InvalidationSet& other); | 140 void combine(const InvalidationSet& other); |
| 139 | 141 |
| 142 protected: |
| 143 explicit InvalidationSet(InvalidationType); |
| 144 |
| 140 ~InvalidationSet() | 145 ~InvalidationSet() |
| 141 { | 146 { |
| 142 RELEASE_ASSERT(m_isAlive); | 147 RELEASE_ASSERT(m_isAlive); |
| 143 m_isAlive = false; | 148 m_isAlive = false; |
| 144 } | 149 } |
| 145 | 150 |
| 146 protected: | |
| 147 explicit InvalidationSet(InvalidationType); | |
| 148 | |
| 149 private: | 151 private: |
| 150 void destroy(); | 152 void destroy(); |
| 151 | 153 |
| 152 HashSet<AtomicString>& ensureClassSet(); | 154 HashSet<AtomicString>& ensureClassSet(); |
| 153 HashSet<AtomicString>& ensureIdSet(); | 155 HashSet<AtomicString>& ensureIdSet(); |
| 154 HashSet<AtomicString>& ensureTagNameSet(); | 156 HashSet<AtomicString>& ensureTagNameSet(); |
| 155 HashSet<AtomicString>& ensureAttributeSet(); | 157 HashSet<AtomicString>& ensureAttributeSet(); |
| 156 | 158 |
| 159 // Implement reference counting manually so we can call a derived |
| 160 // class destructor when the reference count decreases to 0. |
| 161 // If we use RefCounted instead, at least one of our compilers |
| 162 // requires the ability for RefCounted<InvalidationSet>::deref() |
| 163 // to call ~InvalidationSet(), but this is not a virtual call. |
| 164 int m_refCount; |
| 165 |
| 157 // FIXME: optimize this if it becomes a memory issue. | 166 // FIXME: optimize this if it becomes a memory issue. |
| 158 std::unique_ptr<HashSet<AtomicString>> m_classes; | 167 std::unique_ptr<HashSet<AtomicString>> m_classes; |
| 159 std::unique_ptr<HashSet<AtomicString>> m_ids; | 168 std::unique_ptr<HashSet<AtomicString>> m_ids; |
| 160 std::unique_ptr<HashSet<AtomicString>> m_tagNames; | 169 std::unique_ptr<HashSet<AtomicString>> m_tagNames; |
| 161 std::unique_ptr<HashSet<AtomicString>> m_attributes; | 170 std::unique_ptr<HashSet<AtomicString>> m_attributes; |
| 162 | 171 |
| 163 unsigned m_type : 1; | 172 unsigned m_type : 1; |
| 164 | 173 |
| 165 // If true, all descendants might be invalidated, so a full subtree recalc i
s required. | 174 // If true, all descendants might be invalidated, so a full subtree recalc i
s required. |
| 166 unsigned m_allDescendantsMightBeInvalid : 1; | 175 unsigned m_allDescendantsMightBeInvalid : 1; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 InvalidationSetVector descendants; | 241 InvalidationSetVector descendants; |
| 233 InvalidationSetVector siblings; | 242 InvalidationSetVector siblings; |
| 234 }; | 243 }; |
| 235 | 244 |
| 236 DEFINE_TYPE_CASTS(DescendantInvalidationSet, InvalidationSet, value, value->isDe
scendantInvalidationSet(), value.isDescendantInvalidationSet()); | 245 DEFINE_TYPE_CASTS(DescendantInvalidationSet, InvalidationSet, value, value->isDe
scendantInvalidationSet(), value.isDescendantInvalidationSet()); |
| 237 DEFINE_TYPE_CASTS(SiblingInvalidationSet, InvalidationSet, value, value->isSibli
ngInvalidationSet(), value.isSiblingInvalidationSet()); | 246 DEFINE_TYPE_CASTS(SiblingInvalidationSet, InvalidationSet, value, value->isSibli
ngInvalidationSet(), value.isSiblingInvalidationSet()); |
| 238 | 247 |
| 239 } // namespace blink | 248 } // namespace blink |
| 240 | 249 |
| 241 #endif // InvalidationSet_h | 250 #endif // InvalidationSet_h |
| OLD | NEW |