Title: [229332] trunk/Source/WebCore
Revision
229332
Author
an...@apple.com
Date
2018-03-06 11:41:35 -0800 (Tue, 06 Mar 2018)

Log 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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (229331 => 229332)


--- trunk/Source/WebCore/ChangeLog	2018-03-06 19:14:10 UTC (rev 229331)
+++ trunk/Source/WebCore/ChangeLog	2018-03-06 19:41:35 UTC (rev 229332)
@@ -1,3 +1,23 @@
+2018-03-06  Antti Koivisto  <an...@apple.com>
+
+        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.
+
 2018-03-06  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         Change the type of SVGToOTFFontConverter::m_weight to be not a char

Modified: trunk/Source/WebCore/css/DocumentRuleSets.cpp (229331 => 229332)


--- trunk/Source/WebCore/css/DocumentRuleSets.cpp	2018-03-06 19:14:10 UTC (rev 229331)
+++ trunk/Source/WebCore/css/DocumentRuleSets.cpp	2018-03-06 19:41:35 UTC (rev 229332)
@@ -169,6 +169,7 @@
 
     m_classInvalidationRuleSets.clear();
     m_attributeInvalidationRuleSets.clear();
+    m_cachedHasComplexSelectorsForStyleAttribute = std::nullopt;
 
     m_features.shrinkToFit();
 }
@@ -210,4 +211,23 @@
     return ensureInvalidationRuleSets(attributeName, m_attributeInvalidationRuleSets, m_features.attributeRules);
 }
 
+bool DocumentRuleSets::hasComplexSelectorsForStyleAttribute() const
+{
+    auto compute = [&] {
+        auto* ruleSets = attributeInvalidationRuleSets(HTMLNames::styleAttr->localName());
+        if (!ruleSets)
+            return false;
+        for (auto& ruleSet : *ruleSets) {
+            if (ruleSet.matchElement != MatchElement::Subject)
+                return true;
+        }
+        return false;
+    };
+
+    if (!m_cachedHasComplexSelectorsForStyleAttribute)
+        m_cachedHasComplexSelectorsForStyleAttribute = compute();
+
+    return *m_cachedHasComplexSelectorsForStyleAttribute;
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/css/DocumentRuleSets.h (229331 => 229332)


--- trunk/Source/WebCore/css/DocumentRuleSets.h	2018-03-06 19:14:10 UTC (rev 229331)
+++ trunk/Source/WebCore/css/DocumentRuleSets.h	2018-03-06 19:41:35 UTC (rev 229332)
@@ -62,6 +62,8 @@
     const Vector<InvalidationRuleSet>* classInvalidationRuleSets(const AtomicString& className) const;
     const Vector<InvalidationRuleSet>* attributeInvalidationRuleSets(const AtomicString& attributeName) const;
 
+    bool hasComplexSelectorsForStyleAttribute() const;
+
     void setIsForShadowScope() { m_isForShadowScope = true; }
 
     void setUsesSharedUserStyle(bool b) { m_usesSharedUserStyle = b; }
@@ -94,6 +96,7 @@
     mutable std::unique_ptr<RuleSet> m_uncommonAttributeRuleSet;
     mutable HashMap<AtomicString, std::unique_ptr<Vector<InvalidationRuleSet>>> m_classInvalidationRuleSets;
     mutable HashMap<AtomicString, std::unique_ptr<Vector<InvalidationRuleSet>>> m_attributeInvalidationRuleSets;
+    mutable std::optional<bool> m_cachedHasComplexSelectorsForStyleAttribute;
 };
 
 inline const RuleFeatureSet& DocumentRuleSets::features() const

Modified: trunk/Source/WebCore/dom/StyledElement.cpp (229331 => 229332)


--- trunk/Source/WebCore/dom/StyledElement.cpp	2018-03-06 19:14:10 UTC (rev 229331)
+++ trunk/Source/WebCore/dom/StyledElement.cpp	2018-03-06 19:41:35 UTC (rev 229332)
@@ -146,19 +146,6 @@
     InspectorInstrumentation::didInvalidateStyleAttr(document(), *this);
 }
 
-static bool shouldSynchronizeStyleAttributeImmediatelyForInvalidation(StyledElement& element)
-{
-    // In rare case there is a complex attribute selector targeting style attribute (like "[style] ~ div") we need to synchronize immediately.
-    auto* ruleSets = element.styleResolver().ruleSets().attributeInvalidationRuleSets(styleAttr->localName());
-    if (!ruleSets)
-        return false;
-    for (auto& ruleSet : *ruleSets) {
-        if (ruleSet.matchElement != MatchElement::Subject)
-            return true;
-    }
-    return false;
-}
-
 void StyledElement::invalidateStyleAttribute()
 {
     if (usesStyleBasedEditability(*inlineStyle()))
@@ -167,7 +154,8 @@
     elementData()->setStyleAttributeIsDirty(true);
     invalidateStyle();
 
-    if (shouldSynchronizeStyleAttributeImmediatelyForInvalidation(*this)) {
+    // In the rare case of selectors like "[style] ~ div" we need to synchronize immediately to invalidate.
+    if (styleResolver().ruleSets().hasComplexSelectorsForStyleAttribute()) {
         if (auto* inlineStyle = this->inlineStyle()) {
             elementData()->setStyleAttributeIsDirty(false);
             auto newValue = inlineStyle->asText();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to