Title: [292639] trunk/Source/WebCore
Revision
292639
Author
obru...@igalia.com
Date
2022-04-08 15:47:08 -0700 (Fri, 08 Apr 2022)

Log Message

[css-cascade] Sort deferred properties at the end of CSSPropertyID enum
https://bugs.webkit.org/show_bug.cgi?id=238345

Reviewed by Darin Adler.

Bug 238260 will optimize the logic for cascading deferred properties.
This sorts them at the end, after low priority ones, which will allow
some further optimizations.
This is in preparation of bug 238260, which plans to turn all logical
and physical properties into deferred.

No new tests since there should be no change in behavior.

* css/makeprop.pl:
(sortByDescendingPriorityAndName):
Sort deferred properties at the end of CSSPropertyID enum.
Add firstHighPriorityProperty, firstLowPriorityProperty,
lastLowPriorityProperty, firstDeferredProperty and lastDeferredProperty.

* style/PropertyCascade.cpp:
(WebCore::Style::PropertyCascade::set):
(WebCore::Style::PropertyCascade::setDeferred):
(WebCore::Style::PropertyCascade::addMatch):
(WebCore::Style::shouldApplyPropertyInParseOrder): Deleted.
Delete shouldApplyPropertyInParseOrder(), since instead we can just
compare the CSSPropertyId and firstDeferredProperty with < or >=.

* style/PropertyCascade.h:
(WebCore::Style::PropertyCascade::hasNormalProperty const):
(WebCore::Style::PropertyCascade::normalProperty const):
(WebCore::Style::PropertyCascade::hasDeferredProperty const):
(WebCore::Style::PropertyCascade::hasProperty const): Deleted.
(WebCore::Style::PropertyCascade::property const): Deleted.
Rename hasProperty() and property() to hasNormalProperty() and
normalProperty(), to make it clear they are not for deferred properties.
Reduce the size of m_properties array and m_propertyIsPresent bitset,
since they don't need to include deferred properties.

* style/StyleBuilder.cpp:
(WebCore::Style::Builder::applyAllProperties):
(WebCore::Style::Builder::applyHighPriorityProperties):
(WebCore::Style::Builder::applyNonHighPriorityProperties):
(WebCore::Style::Builder::applyPropertiesImpl):
(WebCore::Style::Builder::applyProperty):
(WebCore::Style::Builder::applyLowPriorityProperties): Deleted.
Rename applyLowPriorityProperties() to applyNonHighPriorityProperties()
to make it clear that it includes custom and deferred properties.
Use the new firstHighPriorityProperty and lastLowPriorityProperty
constants for clarity and to skip deferred properties.
Rename hasProperty() and property() to hasNormalProperty() and
normalProperty(), to make it clear they are not for deferred properties.

* style/StyleBuilder.h:
Rename applyLowPriorityProperties() to applyNonHighPriorityProperties()
to make it clear that it includes custom and deferred properties.

* style/StyleResolver.cpp:
(WebCore::Style::Resolver::applyMatchedProperties):
Rename applyLowPriorityProperties() to applyNonHighPriorityProperties()
to make it clear that it includes custom and deferred properties.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (292638 => 292639)


--- trunk/Source/WebCore/ChangeLog	2022-04-08 22:07:25 UTC (rev 292638)
+++ trunk/Source/WebCore/ChangeLog	2022-04-08 22:47:08 UTC (rev 292639)
@@ -1,3 +1,66 @@
+2022-04-08  Oriol Brufau  <obru...@igalia.com>
+
+        [css-cascade] Sort deferred properties at the end of CSSPropertyID enum
+        https://bugs.webkit.org/show_bug.cgi?id=238345
+
+        Reviewed by Darin Adler.
+
+        Bug 238260 will optimize the logic for cascading deferred properties.
+        This sorts them at the end, after low priority ones, which will allow
+        some further optimizations.
+        This is in preparation of bug 238260, which plans to turn all logical
+        and physical properties into deferred.
+
+        No new tests since there should be no change in behavior.
+
+        * css/makeprop.pl:
+        (sortByDescendingPriorityAndName):
+        Sort deferred properties at the end of CSSPropertyID enum.
+        Add firstHighPriorityProperty, firstLowPriorityProperty,
+        lastLowPriorityProperty, firstDeferredProperty and lastDeferredProperty.
+
+        * style/PropertyCascade.cpp:
+        (WebCore::Style::PropertyCascade::set):
+        (WebCore::Style::PropertyCascade::setDeferred):
+        (WebCore::Style::PropertyCascade::addMatch):
+        (WebCore::Style::shouldApplyPropertyInParseOrder): Deleted.
+        Delete shouldApplyPropertyInParseOrder(), since instead we can just
+        compare the CSSPropertyId and firstDeferredProperty with < or >=.
+
+        * style/PropertyCascade.h:
+        (WebCore::Style::PropertyCascade::hasNormalProperty const):
+        (WebCore::Style::PropertyCascade::normalProperty const):
+        (WebCore::Style::PropertyCascade::hasDeferredProperty const):
+        (WebCore::Style::PropertyCascade::hasProperty const): Deleted.
+        (WebCore::Style::PropertyCascade::property const): Deleted.
+        Rename hasProperty() and property() to hasNormalProperty() and
+        normalProperty(), to make it clear they are not for deferred properties.
+        Reduce the size of m_properties array and m_propertyIsPresent bitset,
+        since they don't need to include deferred properties.
+
+        * style/StyleBuilder.cpp:
+        (WebCore::Style::Builder::applyAllProperties):
+        (WebCore::Style::Builder::applyHighPriorityProperties):
+        (WebCore::Style::Builder::applyNonHighPriorityProperties):
+        (WebCore::Style::Builder::applyPropertiesImpl):
+        (WebCore::Style::Builder::applyProperty):
+        (WebCore::Style::Builder::applyLowPriorityProperties): Deleted.
+        Rename applyLowPriorityProperties() to applyNonHighPriorityProperties()
+        to make it clear that it includes custom and deferred properties.
+        Use the new firstHighPriorityProperty and lastLowPriorityProperty
+        constants for clarity and to skip deferred properties.
+        Rename hasProperty() and property() to hasNormalProperty() and
+        normalProperty(), to make it clear they are not for deferred properties.
+
+        * style/StyleBuilder.h:
+        Rename applyLowPriorityProperties() to applyNonHighPriorityProperties()
+        to make it clear that it includes custom and deferred properties.
+
+        * style/StyleResolver.cpp:
+        (WebCore::Style::Resolver::applyMatchedProperties):
+        Rename applyLowPriorityProperties() to applyNonHighPriorityProperties()
+        to make it clear that it includes custom and deferred properties.
+
 2022-04-08  Chris Dumez  <cdu...@apple.com>
 
         Simplify / Optimize the whitespace cache implementation

Modified: trunk/Source/WebCore/css/makeprop.pl (292638 => 292639)


--- trunk/Source/WebCore/css/makeprop.pl	2022-04-08 22:07:25 UTC (rev 292638)
+++ trunk/Source/WebCore/css/makeprop.pl	2022-04-08 22:47:08 UTC (rev 292639)
@@ -359,6 +359,14 @@
     if (!!$nameIsHighPriority{$a} > !!$nameIsHighPriority{$b}) {
         return -1;
     }
+    # Defer names with a related property to the back
+    if (!!$relatedProperty{$a} < !!$relatedProperty{$b}) {
+        return -1;
+    }
+    if (!!$relatedProperty{$a} > !!$relatedProperty{$b}) {
+        return 1;
+    }
+    # Sort sunken names at the end of their priority bucket
     if (!!$namePriorityShouldSink{$a} < !!$namePriorityShouldSink{$b}) {
         return -1;
     }
@@ -834,9 +842,24 @@
 my $first = $numPredefinedProperties;
 my $i = $numPredefinedProperties;
 my $maxLen = 0;
+my $firstHighPriorityPropertyName;
 my $lastHighPriorityPropertyName;
+my $firstLowPriorityPropertyName;
+my $lastLowPriorityPropertyName;
+my $firstDeferredPropertyName;
+my $lastDeferredPropertyName;
 foreach my $name (@names) {
-  $lastHighPriorityPropertyName = $name if $nameIsHighPriority{$name}; # Assumes that @names is sorted by descending priorities.
+  # Assumes that @names is sorted by descending priorities.
+  if ($nameIsHighPriority{$name}) {
+    $firstHighPriorityPropertyName = $name if !$firstHighPriorityPropertyName;
+    $lastHighPriorityPropertyName = $name;
+  } elsif (!$relatedProperty{$name}) {
+    $firstLowPriorityPropertyName = $name if !$firstLowPriorityPropertyName;
+    $lastLowPriorityPropertyName = $name;
+  } else {
+    $firstDeferredPropertyName = $name if !$firstDeferredPropertyName;
+    $lastDeferredPropertyName = $name;
+  }
   print HEADER "    CSSProperty" . $nameToId{$name} . " = " . $i . ",\n";
   $i = $i + 1;
   if (length($name) > $maxLen) {
@@ -851,7 +874,12 @@
 print HEADER "const int numCSSProperties = $num;\n";
 print HEADER "const int lastCSSProperty = $last;\n";
 print HEADER "const size_t maxCSSPropertyNameLength = $maxLen;\n";
-print HEADER "const CSSPropertyID lastHighPriorityProperty = CSSProperty" . $nameToId{$lastHighPriorityPropertyName} . ";\n\n";
+print HEADER "const CSSPropertyID firstHighPriorityProperty = CSSProperty" . $nameToId{$firstHighPriorityPropertyName} . ";\n";
+print HEADER "const CSSPropertyID lastHighPriorityProperty = CSSProperty" . $nameToId{$lastHighPriorityPropertyName} . ";\n";
+print HEADER "const CSSPropertyID firstLowPriorityProperty = CSSProperty" . $nameToId{$firstLowPriorityPropertyName} . ";\n";
+print HEADER "const CSSPropertyID lastLowPriorityProperty = CSSProperty" . $nameToId{$lastLowPriorityPropertyName} . ";\n";
+print HEADER "const CSSPropertyID firstDeferredProperty = CSSProperty" . $nameToId{$firstDeferredPropertyName} . ";\n";
+print HEADER "const CSSPropertyID lastDeferredProperty = CSSProperty" . $nameToId{$lastDeferredPropertyName} . ";\n\n";
 
 print HEADER "static const CSSPropertyID computedPropertyIDs[] = {\n";
 my $numComputedPropertyIDs = 0;

Modified: trunk/Source/WebCore/style/PropertyCascade.cpp (292638 => 292639)


--- trunk/Source/WebCore/style/PropertyCascade.cpp	2022-04-08 22:07:25 UTC (rev 292638)
+++ trunk/Source/WebCore/style/PropertyCascade.cpp	2022-04-08 22:47:08 UTC (rev 292639)
@@ -38,11 +38,6 @@
 namespace WebCore {
 namespace Style {
 
-static inline bool shouldApplyPropertyInParseOrder(CSSPropertyID propertyID)
-{
-    return getRelatedPropertyId(propertyID) != CSSPropertyInvalid;
-}
-
 PropertyCascade::PropertyCascade(const MatchResult& matchResult, CascadeLevel maximumCascadeLevel, IncludedProperties includedProperties, Direction direction)
     : m_matchResult(matchResult)
     , m_includedProperties(includedProperties)
@@ -108,7 +103,7 @@
         id = CSSProperty::resolveDirectionAwareProperty(id, direction.textDirection, direction.writingMode);
     }
 
-    ASSERT(!shouldApplyPropertyInParseOrder(id));
+    ASSERT(id < firstDeferredProperty);
 
     auto& property = m_properties[id];
     ASSERT(id < m_propertyIsPresent.size());
@@ -139,7 +134,7 @@
 void PropertyCascade::setDeferred(CSSPropertyID id, CSSValue& cssValue, const MatchedProperties& matchedProperties, CascadeLevel cascadeLevel)
 {
     ASSERT(!CSSProperty::isDirectionAwareProperty(id));
-    ASSERT(shouldApplyPropertyInParseOrder(id));
+    ASSERT(id >= firstDeferredProperty);
 
     Property property;
     memset(property.cssValue, 0, sizeof(property.cssValue));
@@ -192,10 +187,10 @@
         if (propertyAllowlist == PropertyAllowlist::Marker && !isValidMarkerStyleProperty(propertyID))
             continue;
 
-        if (shouldApplyPropertyInParseOrder(propertyID))
+        if (propertyID < firstDeferredProperty)
+            set(propertyID, *current.value(), matchedProperties, cascadeLevel);
+        else
             setDeferred(propertyID, *current.value(), matchedProperties, cascadeLevel);
-        else
-            set(propertyID, *current.value(), matchedProperties, cascadeLevel);
     }
 
     return hasImportantProperties;

Modified: trunk/Source/WebCore/style/PropertyCascade.h (292638 => 292639)


--- trunk/Source/WebCore/style/PropertyCascade.h	2022-04-08 22:07:25 UTC (rev 292638)
+++ trunk/Source/WebCore/style/PropertyCascade.h	2022-04-08 22:47:08 UTC (rev 292639)
@@ -59,8 +59,8 @@
         CSSValue* cssValue[3]; // Values for link match states MatchDefault, MatchLink and MatchVisited
     };
 
-    bool hasProperty(CSSPropertyID) const;
-    const Property& property(CSSPropertyID) const;
+    bool hasNormalProperty(CSSPropertyID) const;
+    const Property& normalProperty(CSSPropertyID) const;
 
     bool hasDeferredProperty(CSSPropertyID) const;
     const Property& deferredProperty(CSSPropertyID) const;
@@ -92,8 +92,8 @@
     mutable Direction m_direction;
     mutable bool m_directionIsUnresolved { true };
 
-    Property m_properties[numCSSProperties + 2];
-    std::bitset<numCSSProperties + 2> m_propertyIsPresent;
+    Property m_properties[firstDeferredProperty];
+    std::bitset<firstDeferredProperty> m_propertyIsPresent;
 
     Vector<Property, 8> m_deferredProperties;
     HashMap<CSSPropertyID, unsigned> m_deferredPropertiesIndices;
@@ -101,19 +101,21 @@
     HashMap<AtomString, Property> m_customProperties;
 };
 
-inline bool PropertyCascade::hasProperty(CSSPropertyID id) const
+inline bool PropertyCascade::hasNormalProperty(CSSPropertyID id) const
 {
-    ASSERT(id < m_propertyIsPresent.size());
+    ASSERT(id < firstDeferredProperty);
     return m_propertyIsPresent[id];
 }
 
-inline const PropertyCascade::Property& PropertyCascade::property(CSSPropertyID id) const
+inline const PropertyCascade::Property& PropertyCascade::normalProperty(CSSPropertyID id) const
 {
+    ASSERT(hasNormalProperty(id));
     return m_properties[id];
 }
 
 inline bool PropertyCascade::hasDeferredProperty(CSSPropertyID id) const
 {
+    ASSERT(id >= firstDeferredProperty);
     return m_deferredPropertiesIndices.contains(id);
 }
 

Modified: trunk/Source/WebCore/style/StyleBuilder.cpp (292638 => 292639)


--- trunk/Source/WebCore/style/StyleBuilder.cpp	2022-04-08 22:07:25 UTC (rev 292638)
+++ trunk/Source/WebCore/style/StyleBuilder.cpp	2022-04-08 22:47:08 UTC (rev 292639)
@@ -91,7 +91,7 @@
 void Builder::applyAllProperties()
 {
     applyHighPriorityProperties();
-    applyLowPriorityProperties();
+    applyNonHighPriorityProperties();
 }
 
 // High priority properties may affect resolution of other properties (they are mostly font related).
@@ -105,17 +105,17 @@
     applyProperties(CSSPropertyColorScheme, CSSPropertyColorScheme);
 #endif
 
-    applyProperties(firstCSSProperty, lastHighPriorityProperty);
+    applyProperties(firstHighPriorityProperty, lastHighPriorityProperty);
 
     m_state.updateFont();
 }
 
-void Builder::applyLowPriorityProperties()
+void Builder::applyNonHighPriorityProperties()
 {
     ASSERT(!m_state.fontDirty());
 
     applyCustomProperties();
-    applyProperties(firstLowPriorityProperty, lastCSSProperty);
+    applyProperties(firstLowPriorityProperty, lastLowPriorityProperty);
     applyDeferredProperties();
 
     ASSERT(!m_state.fontDirty());
@@ -140,10 +140,10 @@
 {
     for (int id = firstProperty; id <= lastProperty; ++id) {
         CSSPropertyID propertyID = static_cast<CSSPropertyID>(id);
-        if (!m_cascade.hasProperty(propertyID))
+        if (!m_cascade.hasNormalProperty(propertyID))
             continue;
         ASSERT(propertyID != CSSPropertyCustom);
-        auto& property = m_cascade.property(propertyID);
+        auto& property = m_cascade.normalProperty(propertyID);
 
         if (trackCycles == CustomPropertyCycleTracking::Enabled) {
             if (UNLIKELY(m_state.m_inProgressProperties.get(propertyID))) {
@@ -316,10 +316,12 @@
                     applyRollbackCascadeProperty(property, linkMatchMask);
                     return;
                 }
-            } else if (rollbackCascade->hasProperty(id)) {
-                auto& property = rollbackCascade->property(id);
-                applyRollbackCascadeProperty(property, linkMatchMask);
-                return;
+            } else if (id < firstDeferredProperty) {
+                if (rollbackCascade->hasNormalProperty(id)) {
+                    auto& property = rollbackCascade->normalProperty(id);
+                    applyRollbackCascadeProperty(property, linkMatchMask);
+                    return;
+                }
             } else if (rollbackCascade->hasDeferredProperty(id)) {
                 auto& property = rollbackCascade->deferredProperty(id);
                 applyRollbackCascadeProperty(property, linkMatchMask);

Modified: trunk/Source/WebCore/style/StyleBuilder.h (292638 => 292639)


--- trunk/Source/WebCore/style/StyleBuilder.h	2022-04-08 22:07:25 UTC (rev 292638)
+++ trunk/Source/WebCore/style/StyleBuilder.h	2022-04-08 22:47:08 UTC (rev 292639)
@@ -40,7 +40,7 @@
 
     void applyAllProperties();
     void applyHighPriorityProperties();
-    void applyLowPriorityProperties();
+    void applyNonHighPriorityProperties();
 
     void applyProperty(CSSPropertyID propertyID) { applyProperties(propertyID, propertyID); }
     void applyCustomProperty(const String& name);

Modified: trunk/Source/WebCore/style/StyleResolver.cpp (292638 => 292639)


--- trunk/Source/WebCore/style/StyleResolver.cpp	2022-04-08 22:07:25 UTC (rev 292638)
+++ trunk/Source/WebCore/style/StyleResolver.cpp	2022-04-08 22:47:08 UTC (rev 292639)
@@ -628,7 +628,7 @@
         return;
     }
 
-    builder.applyLowPriorityProperties();
+    builder.applyNonHighPriorityProperties();
 
     for (auto& contentAttribute : builder.state().registeredContentAttributes())
         ruleSets().mutableFeatures().registerContentAttribute(contentAttribute);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to