Chromium Code Reviews| Index: Source/core/css/invalidation/DescendantInvalidationSet.cpp |
| diff --git a/Source/core/css/invalidation/DescendantInvalidationSet.cpp b/Source/core/css/invalidation/DescendantInvalidationSet.cpp |
| index 232f3cfe9b14348d607baf9ee7162d9ea459874d..c5bd54bfe261b7d9dd7274d8789f6010748cab73 100644 |
| --- a/Source/core/css/invalidation/DescendantInvalidationSet.cpp |
| +++ b/Source/core/css/invalidation/DescendantInvalidationSet.cpp |
| @@ -33,6 +33,9 @@ |
| #include "core/css/resolver/StyleResolver.h" |
| #include "core/dom/Element.h" |
| +#include "core/inspector/InspectorTraceEvents.h" |
| +#include "platform/TracedValue.h" |
| +#include "wtf/text/StringBuilder.h" |
| namespace blink { |
| @@ -43,35 +46,51 @@ DescendantInvalidationSet::DescendantInvalidationSet() |
| { |
| } |
| +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
|
| bool DescendantInvalidationSet::invalidatesElement(Element& element) const |
| { |
| if (m_allDescendantsMightBeInvalid) |
| return true; |
| - if (m_tagNames && m_tagNames->contains(element.tagQName().localName())) |
| + if (m_tagNames && m_tagNames->contains(element.tagQName().localName())) { |
| + if (styleInvalidationTracingEnabled == StyleInvalidationTracingEnabled) |
| + TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART(element, InvalidationSetMatchedTagName, element.tagQName().localName()); |
| return true; |
| + } |
| - if (element.hasID() && m_ids && m_ids->contains(element.idForStyleResolution())) |
| + if (element.hasID() && m_ids && m_ids->contains(element.idForStyleResolution())) { |
| + if (styleInvalidationTracingEnabled == StyleInvalidationTracingEnabled) |
| + TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART(element, InvalidationSetMatchedId, element.idForStyleResolution()); |
| return true; |
| + } |
| if (element.hasClass() && m_classes) { |
| const SpaceSplitString& classNames = element.classNames(); |
| for (WillBeHeapHashSet<AtomicString>::const_iterator it = m_classes->begin(); it != m_classes->end(); ++it) { |
| - if (classNames.contains(*it)) |
| + if (classNames.contains(*it)) { |
| + if (styleInvalidationTracingEnabled == StyleInvalidationTracingEnabled) |
| + TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART(element, InvalidationSetMatchedClass, *it); |
| return true; |
| + } |
| } |
| } |
| if (element.hasAttributes() && m_attributes) { |
| for (WillBeHeapHashSet<AtomicString>::const_iterator it = m_attributes->begin(); it != m_attributes->end(); ++it) { |
| - if (element.hasAttribute(*it)) |
| + if (element.hasAttribute(*it)) { |
| + if (styleInvalidationTracingEnabled == StyleInvalidationTracingEnabled) |
| + TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART(element, InvalidationSetMatchedAttribute, *it); |
| return true; |
| + } |
| } |
| } |
| return false; |
| } |
| +template bool DescendantInvalidationSet::invalidatesElement<StyleInvalidationTracingEnabled>(Element&) const; |
| +template bool DescendantInvalidationSet::invalidatesElement<StyleInvalidationTracingDisabled>(Element&) const; |
| + |
| void DescendantInvalidationSet::combine(const DescendantInvalidationSet& other) |
| { |
| // No longer bother combining data structures, since the whole subtree is deemed invalid. |
| @@ -193,33 +212,54 @@ void DescendantInvalidationSet::trace(Visitor* visitor) |
| #endif |
| } |
| -#ifndef NDEBUG |
| -void DescendantInvalidationSet::show() const |
| +void DescendantInvalidationSet::toTracedValue(TracedValue* value) const |
| { |
| - fprintf(stderr, "DescendantInvalidationSet { "); |
| + value->beginDictionary(); |
| + |
| if (m_allDescendantsMightBeInvalid) |
| - fprintf(stderr, "* "); |
| + value->setBoolean("allDescendantsMightBeInvalid", true); |
| if (m_customPseudoInvalid) |
| - fprintf(stderr, "::custom "); |
| + value->setBoolean("customPseudoInvalid", true); |
| if (m_treeBoundaryCrossing) |
| - fprintf(stderr, "::shadow/deep/ "); |
| + value->setBoolean("treeBoundaryCrossing", true); |
| + |
| if (m_ids) { |
| - for (WillBeHeapHashSet<AtomicString>::const_iterator it = m_ids->begin(); it != m_ids->end(); ++it) |
| - fprintf(stderr, "#%s ", (*it).ascii().data()); |
| + value->beginArray("ids"); |
| + for (const auto& id : *m_ids) |
| + value->pushString(id); |
| + value->endArray(); |
| } |
| + |
| if (m_classes) { |
| - for (WillBeHeapHashSet<AtomicString>::const_iterator it = m_classes->begin(); it != m_classes->end(); ++it) |
| - fprintf(stderr, ".%s ", (*it).ascii().data()); |
| + value->beginArray("classes"); |
| + for (const auto& className : *m_classes) |
| + value->pushString(className); |
| + value->endArray(); |
| } |
| + |
| if (m_tagNames) { |
| - for (WillBeHeapHashSet<AtomicString>::const_iterator it = m_tagNames->begin(); it != m_tagNames->end(); ++it) |
| - fprintf(stderr, "<%s> ", (*it).ascii().data()); |
| + value->beginArray("tagNames"); |
| + for (const auto& tagName : *m_tagNames) |
| + value->pushString(tagName); |
| + value->endArray(); |
| } |
| + |
| if (m_attributes) { |
| - for (WillBeHeapHashSet<AtomicString>::const_iterator it = m_attributes->begin(); it != m_attributes->end(); ++it) |
| - fprintf(stderr, "[%s] ", (*it).ascii().data()); |
| + value->beginArray("ids"); |
| + for (const auto& attribute : *m_attributes) |
| + value->pushString(attribute); |
| + value->endArray(); |
| } |
| - fprintf(stderr, "}\n"); |
| + |
| + value->endDictionary(); |
| +} |
| + |
| +#ifndef NDEBUG |
| +void DescendantInvalidationSet::show() const |
| +{ |
| + RefPtr<TracedValue> value = TracedValue::create(); |
| + toTracedValue(value.get()); |
| + fprintf(stderr, "%s\n", value->asTraceFormat().ascii().data()); |
| } |
| #endif // NDEBUG |