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 189882565a5ab123e12889f128a64ca8bb10b9f3..0229acf06e1495c25537193231fa7de898037840 100644 |
| --- a/Source/core/css/invalidation/DescendantInvalidationSet.cpp |
| +++ b/Source/core/css/invalidation/DescendantInvalidationSet.cpp |
| @@ -33,9 +33,20 @@ |
| #include "core/css/resolver/StyleResolver.h" |
| #include "core/dom/Element.h" |
| +#include "core/inspector/InspectorTraceEvents.h" |
| +#include "platform/TracedValue.h" |
| +#include "wtf/Compiler.h" |
| +#include "wtf/text/StringBuilder.h" |
| namespace blink { |
| +static const unsigned char* s_tracingEnabled = nullptr; |
| + |
| +void DescendantInvalidationSet::init() |
| +{ |
| + s_tracingEnabled = TRACE_EVENT_API_GET_CATEGORY_ENABLED(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.invalidationTracking")); |
| +} |
| + |
| DescendantInvalidationSet::DescendantInvalidationSet() |
| : m_allDescendantsMightBeInvalid(false) |
| , m_customPseudoInvalid(false) |
| @@ -43,29 +54,41 @@ DescendantInvalidationSet::DescendantInvalidationSet() |
| { |
| } |
| +#define TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(element, reason, singleSelectorPart) \ |
| + if (UNLIKELY(*s_tracingEnabled)) \ |
| + TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART(element, reason, singleSelectorPart); |
| + |
| 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())) { |
| + TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(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())) { |
| + TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(element, InvalidationSetMatchedId, element.idForStyleResolution()); |
| return true; |
| + } |
| if (element.hasClass() && m_classes) { |
| const SpaceSplitString& classNames = element.classNames(); |
| - for (const auto& className : *m_classes) { |
| - if (classNames.contains(className)) |
| + for (WillBeHeapHashSet<AtomicString>::const_iterator it = m_classes->begin(); it != m_classes->end(); ++it) { |
| + if (classNames.contains(*it)) { |
| + TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(element, InvalidationSetMatchedClass, *it); |
| return true; |
| + } |
| } |
| } |
| if (element.hasAttributes() && m_attributes) { |
| - for (const auto& attribute : *m_attributes) { |
| - if (element.hasAttribute(attribute)) |
| + 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
|
| + if (element.hasAttribute(*it)) { |
| + TRACE_STYLE_INVALIDATOR_INVALIDATION_SELECTORPART_IF_ENABLED(element, InvalidationSetMatchedAttribute, *it); |
| return true; |
| + } |
| } |
| } |
| @@ -90,23 +113,27 @@ void DescendantInvalidationSet::combine(const DescendantInvalidationSet& other) |
| setTreeBoundaryCrossing(); |
| if (other.m_classes) { |
| - for (const auto& className : *other.m_classes) |
| - addClass(className); |
| + WillBeHeapHashSet<AtomicString>::const_iterator end = other.m_classes->end(); |
| + for (WillBeHeapHashSet<AtomicString>::const_iterator it = other.m_classes->begin(); it != end; ++it) |
| + addClass(*it); |
| } |
| if (other.m_ids) { |
| - for (const auto& id : *other.m_ids) |
| - addId(id); |
| + WillBeHeapHashSet<AtomicString>::const_iterator end = other.m_ids->end(); |
| + for (WillBeHeapHashSet<AtomicString>::const_iterator it = other.m_ids->begin(); it != end; ++it) |
| + addId(*it); |
| } |
| if (other.m_tagNames) { |
| - for (const auto& tagName : *other.m_tagNames) |
| - addTagName(tagName); |
| + WillBeHeapHashSet<AtomicString>::const_iterator end = other.m_tagNames->end(); |
| + for (WillBeHeapHashSet<AtomicString>::const_iterator it = other.m_tagNames->begin(); it != end; ++it) |
| + addTagName(*it); |
| } |
| if (other.m_attributes) { |
| - for (const auto& attribute : *other.m_attributes) |
| - addAttribute(attribute); |
| + WillBeHeapHashSet<AtomicString>::const_iterator end = other.m_attributes->end(); |
| + for (WillBeHeapHashSet<AtomicString>::const_iterator it = other.m_attributes->begin(); it != end; ++it) |
| + addAttribute(*it); |
| } |
| } |
| @@ -189,33 +216,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) { |
| + value->beginArray("ids"); |
| for (const auto& id : *m_ids) |
| - fprintf(stderr, "#%s ", id.ascii().data()); |
| + value->pushString(id); |
| + value->endArray(); |
| } |
| + |
| if (m_classes) { |
| + value->beginArray("classes"); |
| for (const auto& className : *m_classes) |
| - fprintf(stderr, ".%s ", className.ascii().data()); |
| + value->pushString(className); |
| + value->endArray(); |
| } |
| + |
| if (m_tagNames) { |
| + value->beginArray("tagNames"); |
| for (const auto& tagName : *m_tagNames) |
| - fprintf(stderr, "<%s> ", tagName.ascii().data()); |
| + value->pushString(tagName); |
| + value->endArray(); |
| } |
| + |
| if (m_attributes) { |
| + value->beginArray("ids"); |
| for (const auto& attribute : *m_attributes) |
| - fprintf(stderr, "[%s] ", attribute.ascii().data()); |
| + 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 |