Chromium Code Reviews| 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 15 matching lines...) Expand all Loading... | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/css/invalidation/DescendantInvalidationSet.h" | 32 #include "core/css/invalidation/DescendantInvalidationSet.h" |
| 33 | 33 |
| 34 #include "core/css/resolver/StyleResolver.h" | 34 #include "core/css/resolver/StyleResolver.h" |
| 35 #include "core/dom/Element.h" | 35 #include "core/dom/Element.h" |
| 36 #include "core/inspector/InspectorTraceEvents.h" | |
| 37 #include "platform/TracedValue.h" | |
| 38 #include "wtf/Compiler.h" | |
| 39 #include "wtf/text/StringBuilder.h" | |
| 36 | 40 |
| 37 namespace blink { | 41 namespace blink { |
| 38 | 42 |
| 43 static const unsigned char* s_tracingEnabled = nullptr; | |
| 44 | |
| 45 void DescendantInvalidationSet::init() | |
| 46 { | |
| 47 s_tracingEnabled = TRACE_EVENT_API_GET_CATEGORY_ENABLED(TRACE_DISABLED_BY_DE FAULT("devtools.timeline.invalidationTracking")); | |
| 48 } | |
| 49 | |
| 39 DescendantInvalidationSet::DescendantInvalidationSet() | 50 DescendantInvalidationSet::DescendantInvalidationSet() |
| 40 : m_allDescendantsMightBeInvalid(false) | 51 : m_allDescendantsMightBeInvalid(false) |
| 41 , m_customPseudoInvalid(false) | 52 , m_customPseudoInvalid(false) |
| 42 , m_treeBoundaryCrossing(false) | 53 , m_treeBoundaryCrossing(false) |
| 43 { | 54 { |
| 44 } | 55 } |
| 45 | 56 |
| 57 #define TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(element, re ason, singleSelectorPart) \ | |
| 58 if (UNLIKELY(*s_tracingEnabled)) \ | |
| 59 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART(element, reason, singl eSelectorPart); | |
| 60 | |
| 46 bool DescendantInvalidationSet::invalidatesElement(Element& element) const | 61 bool DescendantInvalidationSet::invalidatesElement(Element& element) const |
| 47 { | 62 { |
| 48 if (m_allDescendantsMightBeInvalid) | 63 if (m_allDescendantsMightBeInvalid) |
| 49 return true; | 64 return true; |
| 50 | 65 |
| 51 if (m_tagNames && m_tagNames->contains(element.tagQName().localName())) | 66 if (m_tagNames && m_tagNames->contains(element.tagQName().localName())) { |
| 67 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(element, In validationSetMatchedTagName, element.tagQName().localName()); | |
| 52 return true; | 68 return true; |
| 69 } | |
| 53 | 70 |
| 54 if (element.hasID() && m_ids && m_ids->contains(element.idForStyleResolution ())) | 71 if (element.hasID() && m_ids && m_ids->contains(element.idForStyleResolution ())) { |
| 72 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(element, In validationSetMatchedId, element.idForStyleResolution()); | |
| 55 return true; | 73 return true; |
| 74 } | |
| 56 | 75 |
| 57 if (element.hasClass() && m_classes) { | 76 if (element.hasClass() && m_classes) { |
| 58 const SpaceSplitString& classNames = element.classNames(); | 77 const SpaceSplitString& classNames = element.classNames(); |
| 59 for (const auto& className : *m_classes) { | 78 for (WillBeHeapHashSet<AtomicString>::const_iterator it = m_classes->beg in(); it != m_classes->end(); ++it) { |
| 60 if (classNames.contains(className)) | 79 if (classNames.contains(*it)) { |
| 80 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(ele ment, InvalidationSetMatchedClass, *it); | |
| 61 return true; | 81 return true; |
| 82 } | |
| 62 } | 83 } |
| 63 } | 84 } |
| 64 | 85 |
| 65 if (element.hasAttributes() && m_attributes) { | 86 if (element.hasAttributes() && m_attributes) { |
| 66 for (const auto& attribute : *m_attributes) { | 87 for (WillBeHeapHashSet<AtomicString>::const_iterator it = m_attributes-> begin(); it != m_attributes->end(); ++it) { |
|
pdr.
2014/10/14 01:36:47
Nit: Is there a reason you can't use auto here?
kouhei (in TOK)
2014/10/14 02:02:10
This was unintended from failed rebase. Thanks for
| |
| 67 if (element.hasAttribute(attribute)) | 88 if (element.hasAttribute(*it)) { |
| 89 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(ele ment, InvalidationSetMatchedAttribute, *it); | |
| 68 return true; | 90 return true; |
| 91 } | |
| 69 } | 92 } |
| 70 } | 93 } |
| 71 | 94 |
| 72 return false; | 95 return false; |
| 73 } | 96 } |
| 74 | 97 |
| 75 void DescendantInvalidationSet::combine(const DescendantInvalidationSet& other) | 98 void DescendantInvalidationSet::combine(const DescendantInvalidationSet& other) |
| 76 { | 99 { |
| 77 // No longer bother combining data structures, since the whole subtree is de emed invalid. | 100 // No longer bother combining data structures, since the whole subtree is de emed invalid. |
| 78 if (wholeSubtreeInvalid()) | 101 if (wholeSubtreeInvalid()) |
| 79 return; | 102 return; |
| 80 | 103 |
| 81 if (other.wholeSubtreeInvalid()) { | 104 if (other.wholeSubtreeInvalid()) { |
| 82 setWholeSubtreeInvalid(); | 105 setWholeSubtreeInvalid(); |
| 83 return; | 106 return; |
| 84 } | 107 } |
| 85 | 108 |
| 86 if (other.customPseudoInvalid()) | 109 if (other.customPseudoInvalid()) |
| 87 setCustomPseudoInvalid(); | 110 setCustomPseudoInvalid(); |
| 88 | 111 |
| 89 if (other.treeBoundaryCrossing()) | 112 if (other.treeBoundaryCrossing()) |
| 90 setTreeBoundaryCrossing(); | 113 setTreeBoundaryCrossing(); |
| 91 | 114 |
| 92 if (other.m_classes) { | 115 if (other.m_classes) { |
| 93 for (const auto& className : *other.m_classes) | 116 WillBeHeapHashSet<AtomicString>::const_iterator end = other.m_classes->e nd(); |
| 94 addClass(className); | 117 for (WillBeHeapHashSet<AtomicString>::const_iterator it = other.m_classe s->begin(); it != end; ++it) |
| 118 addClass(*it); | |
| 95 } | 119 } |
| 96 | 120 |
| 97 if (other.m_ids) { | 121 if (other.m_ids) { |
| 98 for (const auto& id : *other.m_ids) | 122 WillBeHeapHashSet<AtomicString>::const_iterator end = other.m_ids->end() ; |
| 99 addId(id); | 123 for (WillBeHeapHashSet<AtomicString>::const_iterator it = other.m_ids->b egin(); it != end; ++it) |
| 124 addId(*it); | |
| 100 } | 125 } |
| 101 | 126 |
| 102 if (other.m_tagNames) { | 127 if (other.m_tagNames) { |
| 103 for (const auto& tagName : *other.m_tagNames) | 128 WillBeHeapHashSet<AtomicString>::const_iterator end = other.m_tagNames-> end(); |
| 104 addTagName(tagName); | 129 for (WillBeHeapHashSet<AtomicString>::const_iterator it = other.m_tagNam es->begin(); it != end; ++it) |
| 130 addTagName(*it); | |
| 105 } | 131 } |
| 106 | 132 |
| 107 if (other.m_attributes) { | 133 if (other.m_attributes) { |
| 108 for (const auto& attribute : *other.m_attributes) | 134 WillBeHeapHashSet<AtomicString>::const_iterator end = other.m_attributes ->end(); |
| 109 addAttribute(attribute); | 135 for (WillBeHeapHashSet<AtomicString>::const_iterator it = other.m_attrib utes->begin(); it != end; ++it) |
| 136 addAttribute(*it); | |
| 110 } | 137 } |
| 111 } | 138 } |
| 112 | 139 |
| 113 WillBeHeapHashSet<AtomicString>& DescendantInvalidationSet::ensureClassSet() | 140 WillBeHeapHashSet<AtomicString>& DescendantInvalidationSet::ensureClassSet() |
| 114 { | 141 { |
| 115 if (!m_classes) | 142 if (!m_classes) |
| 116 m_classes = adoptPtrWillBeNoop(new WillBeHeapHashSet<AtomicString>); | 143 m_classes = adoptPtrWillBeNoop(new WillBeHeapHashSet<AtomicString>); |
| 117 return *m_classes; | 144 return *m_classes; |
| 118 } | 145 } |
| 119 | 146 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 void DescendantInvalidationSet::trace(Visitor* visitor) | 209 void DescendantInvalidationSet::trace(Visitor* visitor) |
| 183 { | 210 { |
| 184 #if ENABLE(OILPAN) | 211 #if ENABLE(OILPAN) |
| 185 visitor->trace(m_classes); | 212 visitor->trace(m_classes); |
| 186 visitor->trace(m_ids); | 213 visitor->trace(m_ids); |
| 187 visitor->trace(m_tagNames); | 214 visitor->trace(m_tagNames); |
| 188 visitor->trace(m_attributes); | 215 visitor->trace(m_attributes); |
| 189 #endif | 216 #endif |
| 190 } | 217 } |
| 191 | 218 |
| 219 void DescendantInvalidationSet::toTracedValue(TracedValue* value) const | |
| 220 { | |
| 221 value->beginDictionary(); | |
| 222 | |
| 223 if (m_allDescendantsMightBeInvalid) | |
| 224 value->setBoolean("allDescendantsMightBeInvalid", true); | |
| 225 if (m_customPseudoInvalid) | |
| 226 value->setBoolean("customPseudoInvalid", true); | |
| 227 if (m_treeBoundaryCrossing) | |
| 228 value->setBoolean("treeBoundaryCrossing", true); | |
| 229 | |
| 230 if (m_ids) { | |
| 231 value->beginArray("ids"); | |
| 232 for (const auto& id : *m_ids) | |
| 233 value->pushString(id); | |
| 234 value->endArray(); | |
| 235 } | |
| 236 | |
| 237 if (m_classes) { | |
| 238 value->beginArray("classes"); | |
| 239 for (const auto& className : *m_classes) | |
| 240 value->pushString(className); | |
| 241 value->endArray(); | |
| 242 } | |
| 243 | |
| 244 if (m_tagNames) { | |
| 245 value->beginArray("tagNames"); | |
| 246 for (const auto& tagName : *m_tagNames) | |
| 247 value->pushString(tagName); | |
| 248 value->endArray(); | |
| 249 } | |
| 250 | |
| 251 if (m_attributes) { | |
| 252 value->beginArray("ids"); | |
| 253 for (const auto& attribute : *m_attributes) | |
| 254 value->pushString(attribute); | |
| 255 value->endArray(); | |
| 256 } | |
| 257 | |
| 258 value->endDictionary(); | |
| 259 } | |
| 260 | |
| 192 #ifndef NDEBUG | 261 #ifndef NDEBUG |
| 193 void DescendantInvalidationSet::show() const | 262 void DescendantInvalidationSet::show() const |
| 194 { | 263 { |
| 195 fprintf(stderr, "DescendantInvalidationSet { "); | 264 RefPtr<TracedValue> value = TracedValue::create(); |
| 196 if (m_allDescendantsMightBeInvalid) | 265 toTracedValue(value.get()); |
| 197 fprintf(stderr, "* "); | 266 fprintf(stderr, "%s\n", value->asTraceFormat().ascii().data()); |
| 198 if (m_customPseudoInvalid) | |
| 199 fprintf(stderr, "::custom "); | |
| 200 if (m_treeBoundaryCrossing) | |
| 201 fprintf(stderr, "::shadow/deep/ "); | |
| 202 if (m_ids) { | |
| 203 for (const auto& id : *m_ids) | |
| 204 fprintf(stderr, "#%s ", id.ascii().data()); | |
| 205 } | |
| 206 if (m_classes) { | |
| 207 for (const auto& className : *m_classes) | |
| 208 fprintf(stderr, ".%s ", className.ascii().data()); | |
| 209 } | |
| 210 if (m_tagNames) { | |
| 211 for (const auto& tagName : *m_tagNames) | |
| 212 fprintf(stderr, "<%s> ", tagName.ascii().data()); | |
| 213 } | |
| 214 if (m_attributes) { | |
| 215 for (const auto& attribute : *m_attributes) | |
| 216 fprintf(stderr, "[%s] ", attribute.ascii().data()); | |
| 217 } | |
| 218 fprintf(stderr, "}\n"); | |
| 219 } | 267 } |
| 220 #endif // NDEBUG | 268 #endif // NDEBUG |
| 221 | 269 |
| 222 } // namespace blink | 270 } // namespace blink |
| OLD | NEW |