Changeset 229332 in webkit


Ignore:
Timestamp:
Mar 6, 2018, 11:41:35 AM (8 years ago)
Author:
Antti Koivisto
Message:

Cache hasComplexSelectorsForStyleAttribute bit
https://bugs.webkit.org/show_bug.cgi?id=183363

Reviewed by Andreas Kling.

  • css/DocumentRuleSets.cpp:

(WebCore::DocumentRuleSets::collectFeatures const):
(WebCore::DocumentRuleSets::hasComplexSelectorsForStyleAttribute const):

Cache the bit to avoid hash lookups.

  • css/DocumentRuleSets.h:
  • dom/StyledElement.cpp:

(WebCore::StyledElement::invalidateStyleAttribute):
(WebCore::shouldSynchronizeStyleAttributeImmediatelyForInvalidation): Deleted.

Move code to DocumentRuleSets.

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r229328 r229332  
     12018-03-06  Antti Koivisto  <antti@apple.com>
     2
     3        Cache hasComplexSelectorsForStyleAttribute bit
     4        https://bugs.webkit.org/show_bug.cgi?id=183363
     5
     6        Reviewed by Andreas Kling.
     7
     8        * css/DocumentRuleSets.cpp:
     9        (WebCore::DocumentRuleSets::collectFeatures const):
     10        (WebCore::DocumentRuleSets::hasComplexSelectorsForStyleAttribute const):
     11
     12        Cache the bit to avoid hash lookups.
     13
     14        * css/DocumentRuleSets.h:
     15        * dom/StyledElement.cpp:
     16        (WebCore::StyledElement::invalidateStyleAttribute):
     17        (WebCore::shouldSynchronizeStyleAttributeImmediatelyForInvalidation): Deleted.
     18
     19        Move code to DocumentRuleSets.
     20
    1212018-03-06  Myles C. Maxfield  <mmaxfield@apple.com>
    222
  • trunk/Source/WebCore/css/DocumentRuleSets.cpp

    r228313 r229332  
    170170    m_classInvalidationRuleSets.clear();
    171171    m_attributeInvalidationRuleSets.clear();
     172    m_cachedHasComplexSelectorsForStyleAttribute = std::nullopt;
    172173
    173174    m_features.shrinkToFit();
     
    211212}
    212213
     214bool DocumentRuleSets::hasComplexSelectorsForStyleAttribute() const
     215{
     216    auto compute = [&] {
     217        auto* ruleSets = attributeInvalidationRuleSets(HTMLNames::styleAttr->localName());
     218        if (!ruleSets)
     219            return false;
     220        for (auto& ruleSet : *ruleSets) {
     221            if (ruleSet.matchElement != MatchElement::Subject)
     222                return true;
     223        }
     224        return false;
     225    };
     226
     227    if (!m_cachedHasComplexSelectorsForStyleAttribute)
     228        m_cachedHasComplexSelectorsForStyleAttribute = compute();
     229
     230    return *m_cachedHasComplexSelectorsForStyleAttribute;
     231}
     232
    213233} // namespace WebCore
  • trunk/Source/WebCore/css/DocumentRuleSets.h

    r228285 r229332  
    6363    const Vector<InvalidationRuleSet>* attributeInvalidationRuleSets(const AtomicString& attributeName) const;
    6464
     65    bool hasComplexSelectorsForStyleAttribute() const;
     66
    6567    void setIsForShadowScope() { m_isForShadowScope = true; }
    6668
     
    9597    mutable HashMap<AtomicString, std::unique_ptr<Vector<InvalidationRuleSet>>> m_classInvalidationRuleSets;
    9698    mutable HashMap<AtomicString, std::unique_ptr<Vector<InvalidationRuleSet>>> m_attributeInvalidationRuleSets;
     99    mutable std::optional<bool> m_cachedHasComplexSelectorsForStyleAttribute;
    97100};
    98101
  • trunk/Source/WebCore/dom/StyledElement.cpp

    r229307 r229332  
    147147}
    148148
    149 static bool shouldSynchronizeStyleAttributeImmediatelyForInvalidation(StyledElement& element)
    150 {
    151     // In rare case there is a complex attribute selector targeting style attribute (like "[style] ~ div") we need to synchronize immediately.
    152     auto* ruleSets = element.styleResolver().ruleSets().attributeInvalidationRuleSets(styleAttr->localName());
    153     if (!ruleSets)
    154         return false;
    155     for (auto& ruleSet : *ruleSets) {
    156         if (ruleSet.matchElement != MatchElement::Subject)
    157             return true;
    158     }
    159     return false;
    160 }
    161 
    162149void StyledElement::invalidateStyleAttribute()
    163150{
     
    168155    invalidateStyle();
    169156
    170     if (shouldSynchronizeStyleAttributeImmediatelyForInvalidation(*this)) {
     157    // In the rare case of selectors like "[style] ~ div" we need to synchronize immediately to invalidate.
     158    if (styleResolver().ruleSets().hasComplexSelectorsForStyleAttribute()) {
    171159        if (auto* inlineStyle = this->inlineStyle()) {
    172160            elementData()->setStyleAttributeIsDirty(false);
Note: See TracChangeset for help on using the changeset viewer.