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/text/StringBuilder.h" | |
| 36 | 39 |
| 37 namespace blink { | 40 namespace blink { |
| 38 | 41 |
| 39 DescendantInvalidationSet::DescendantInvalidationSet() | 42 DescendantInvalidationSet::DescendantInvalidationSet() |
| 40 : m_allDescendantsMightBeInvalid(false) | 43 : m_allDescendantsMightBeInvalid(false) |
| 41 , m_customPseudoInvalid(false) | 44 , m_customPseudoInvalid(false) |
| 42 , m_treeBoundaryCrossing(false) | 45 , m_treeBoundaryCrossing(false) |
| 43 { | 46 { |
| 44 } | 47 } |
| 45 | 48 |
| 49 template <StyleInvalidationTracingEnabledFlag styleInvalidationTracingEnabled> | |
|
pdr.
2014/10/10 04:36:07
This function is hot and we want it to be as fast
kouhei (in TOK)
2014/10/10 07:15:07
I tried a similar approach but performance regress
| |
| 46 bool DescendantInvalidationSet::invalidatesElement(Element& element) const | 50 bool DescendantInvalidationSet::invalidatesElement(Element& element) const |
| 47 { | 51 { |
| 48 if (m_allDescendantsMightBeInvalid) | 52 if (m_allDescendantsMightBeInvalid) |
| 49 return true; | 53 return true; |
| 50 | 54 |
| 51 if (m_tagNames && m_tagNames->contains(element.tagQName().localName())) | 55 if (m_tagNames && m_tagNames->contains(element.tagQName().localName())) { |
| 56 if (styleInvalidationTracingEnabled == StyleInvalidationTracingEnabled) | |
| 57 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART(element, Invalidat ionSetMatchedTagName, element.tagQName().localName()); | |
| 52 return true; | 58 return true; |
| 59 } | |
| 53 | 60 |
| 54 if (element.hasID() && m_ids && m_ids->contains(element.idForStyleResolution ())) | 61 if (element.hasID() && m_ids && m_ids->contains(element.idForStyleResolution ())) { |
| 62 if (styleInvalidationTracingEnabled == StyleInvalidationTracingEnabled) | |
| 63 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART(element, Invalidat ionSetMatchedId, element.idForStyleResolution()); | |
| 55 return true; | 64 return true; |
| 65 } | |
| 56 | 66 |
| 57 if (element.hasClass() && m_classes) { | 67 if (element.hasClass() && m_classes) { |
| 58 const SpaceSplitString& classNames = element.classNames(); | 68 const SpaceSplitString& classNames = element.classNames(); |
| 59 for (WillBeHeapHashSet<AtomicString>::const_iterator it = m_classes->beg in(); it != m_classes->end(); ++it) { | 69 for (WillBeHeapHashSet<AtomicString>::const_iterator it = m_classes->beg in(); it != m_classes->end(); ++it) { |
| 60 if (classNames.contains(*it)) | 70 if (classNames.contains(*it)) { |
| 71 if (styleInvalidationTracingEnabled == StyleInvalidationTracingE nabled) | |
| 72 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART(element, I nvalidationSetMatchedClass, *it); | |
| 61 return true; | 73 return true; |
| 74 } | |
| 62 } | 75 } |
| 63 } | 76 } |
| 64 | 77 |
| 65 if (element.hasAttributes() && m_attributes) { | 78 if (element.hasAttributes() && m_attributes) { |
| 66 for (WillBeHeapHashSet<AtomicString>::const_iterator it = m_attributes-> begin(); it != m_attributes->end(); ++it) { | 79 for (WillBeHeapHashSet<AtomicString>::const_iterator it = m_attributes-> begin(); it != m_attributes->end(); ++it) { |
| 67 if (element.hasAttribute(*it)) | 80 if (element.hasAttribute(*it)) { |
| 81 if (styleInvalidationTracingEnabled == StyleInvalidationTracingE nabled) | |
| 82 TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART(element, I nvalidationSetMatchedAttribute, *it); | |
| 68 return true; | 83 return true; |
| 84 } | |
| 69 } | 85 } |
| 70 } | 86 } |
| 71 | 87 |
| 72 return false; | 88 return false; |
| 73 } | 89 } |
| 74 | 90 |
| 91 template bool DescendantInvalidationSet::invalidatesElement<StyleInvalidationTra cingEnabled>(Element&) const; | |
| 92 template bool DescendantInvalidationSet::invalidatesElement<StyleInvalidationTra cingDisabled>(Element&) const; | |
| 93 | |
| 75 void DescendantInvalidationSet::combine(const DescendantInvalidationSet& other) | 94 void DescendantInvalidationSet::combine(const DescendantInvalidationSet& other) |
| 76 { | 95 { |
| 77 // No longer bother combining data structures, since the whole subtree is de emed invalid. | 96 // No longer bother combining data structures, since the whole subtree is de emed invalid. |
| 78 if (wholeSubtreeInvalid()) | 97 if (wholeSubtreeInvalid()) |
| 79 return; | 98 return; |
| 80 | 99 |
| 81 if (other.wholeSubtreeInvalid()) { | 100 if (other.wholeSubtreeInvalid()) { |
| 82 setWholeSubtreeInvalid(); | 101 setWholeSubtreeInvalid(); |
| 83 return; | 102 return; |
| 84 } | 103 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 void DescendantInvalidationSet::trace(Visitor* visitor) | 205 void DescendantInvalidationSet::trace(Visitor* visitor) |
| 187 { | 206 { |
| 188 #if ENABLE(OILPAN) | 207 #if ENABLE(OILPAN) |
| 189 visitor->trace(m_classes); | 208 visitor->trace(m_classes); |
| 190 visitor->trace(m_ids); | 209 visitor->trace(m_ids); |
| 191 visitor->trace(m_tagNames); | 210 visitor->trace(m_tagNames); |
| 192 visitor->trace(m_attributes); | 211 visitor->trace(m_attributes); |
| 193 #endif | 212 #endif |
| 194 } | 213 } |
| 195 | 214 |
| 215 void DescendantInvalidationSet::toTracedValue(TracedValue* value) const | |
| 216 { | |
| 217 value->beginDictionary(); | |
| 218 | |
| 219 if (m_allDescendantsMightBeInvalid) | |
| 220 value->setBoolean("allDescendantsMightBeInvalid", true); | |
| 221 if (m_customPseudoInvalid) | |
| 222 value->setBoolean("customPseudoInvalid", true); | |
| 223 if (m_treeBoundaryCrossing) | |
| 224 value->setBoolean("treeBoundaryCrossing", true); | |
| 225 | |
| 226 if (m_ids) { | |
| 227 value->beginArray("ids"); | |
| 228 for (const auto& id : *m_ids) | |
| 229 value->pushString(id); | |
| 230 value->endArray(); | |
| 231 } | |
| 232 | |
| 233 if (m_classes) { | |
| 234 value->beginArray("classes"); | |
| 235 for (const auto& className : *m_classes) | |
| 236 value->pushString(className); | |
| 237 value->endArray(); | |
| 238 } | |
| 239 | |
| 240 if (m_tagNames) { | |
| 241 value->beginArray("tagNames"); | |
| 242 for (const auto& tagName : *m_tagNames) | |
| 243 value->pushString(tagName); | |
| 244 value->endArray(); | |
| 245 } | |
| 246 | |
| 247 if (m_attributes) { | |
| 248 value->beginArray("ids"); | |
| 249 for (const auto& attribute : *m_attributes) | |
| 250 value->pushString(attribute); | |
| 251 value->endArray(); | |
| 252 } | |
| 253 | |
| 254 value->endDictionary(); | |
| 255 } | |
| 256 | |
| 196 #ifndef NDEBUG | 257 #ifndef NDEBUG |
| 197 void DescendantInvalidationSet::show() const | 258 void DescendantInvalidationSet::show() const |
| 198 { | 259 { |
| 199 fprintf(stderr, "DescendantInvalidationSet { "); | 260 RefPtr<TracedValue> value = TracedValue::create(); |
| 200 if (m_allDescendantsMightBeInvalid) | 261 toTracedValue(value.get()); |
| 201 fprintf(stderr, "* "); | 262 fprintf(stderr, "%s\n", value->asTraceFormat().ascii().data()); |
| 202 if (m_customPseudoInvalid) | |
| 203 fprintf(stderr, "::custom "); | |
| 204 if (m_treeBoundaryCrossing) | |
| 205 fprintf(stderr, "::shadow/deep/ "); | |
| 206 if (m_ids) { | |
| 207 for (WillBeHeapHashSet<AtomicString>::const_iterator it = m_ids->begin() ; it != m_ids->end(); ++it) | |
| 208 fprintf(stderr, "#%s ", (*it).ascii().data()); | |
| 209 } | |
| 210 if (m_classes) { | |
| 211 for (WillBeHeapHashSet<AtomicString>::const_iterator it = m_classes->beg in(); it != m_classes->end(); ++it) | |
| 212 fprintf(stderr, ".%s ", (*it).ascii().data()); | |
| 213 } | |
| 214 if (m_tagNames) { | |
| 215 for (WillBeHeapHashSet<AtomicString>::const_iterator it = m_tagNames->be gin(); it != m_tagNames->end(); ++it) | |
| 216 fprintf(stderr, "<%s> ", (*it).ascii().data()); | |
| 217 } | |
| 218 if (m_attributes) { | |
| 219 for (WillBeHeapHashSet<AtomicString>::const_iterator it = m_attributes-> begin(); it != m_attributes->end(); ++it) | |
| 220 fprintf(stderr, "[%s] ", (*it).ascii().data()); | |
| 221 } | |
| 222 fprintf(stderr, "}\n"); | |
| 223 } | 263 } |
| 224 #endif // NDEBUG | 264 #endif // NDEBUG |
| 225 | 265 |
| 226 } // namespace blink | 266 } // namespace blink |
| OLD | NEW |