- Revision
- 285392
- Author
- [email protected]
- Date
- 2021-11-07 10:58:10 -0800 (Sun, 07 Nov 2021)
Log Message
Use narrower types for style scope ordinal and cascade layer priority
https://bugs.webkit.org/show_bug.cgi?id=232797
Reviewed by Alan Bujtas.
This shrinks critical ElementRuleCollector data structures like MatchedRule.
64k layers ought to be enough for anybody (and 256 scopes).
* style/ElementRuleCollector.cpp:
(WebCore::Style::ElementRuleCollector::matchSlottedPseudoElementRules):
(WebCore::Style::ElementRuleCollector::matchPartPseudoElementRulesForScope):
Check the scope depth limits.
* style/ElementRuleCollector.h:
* style/RuleSet.h:
(WebCore::Style::RuleSet::cascadeLayerPriorityForIdentifier const):
(WebCore::Style::RuleSet::cascadeLayerPriorityFor const):
Add a type alias and make it uint16_t.
* style/RuleSetBuilder.cpp:
(WebCore::Style::RuleSetBuilder::updateCascadeLayerPriorities):
* style/StyleScopeOrdinal.h:
(WebCore::Style::operator++):
(WebCore::Style::operator--):
Use int8_t. No realistic case requires more than a handful.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (285391 => 285392)
--- trunk/Source/WebCore/ChangeLog 2021-11-07 18:39:07 UTC (rev 285391)
+++ trunk/Source/WebCore/ChangeLog 2021-11-07 18:58:10 UTC (rev 285392)
@@ -1,3 +1,35 @@
+2021-11-07 Antti Koivisto <[email protected]>
+
+ Use narrower types for style scope ordinal and cascade layer priority
+ https://bugs.webkit.org/show_bug.cgi?id=232797
+
+ Reviewed by Alan Bujtas.
+
+ This shrinks critical ElementRuleCollector data structures like MatchedRule.
+
+ 64k layers ought to be enough for anybody (and 256 scopes).
+
+ * style/ElementRuleCollector.cpp:
+ (WebCore::Style::ElementRuleCollector::matchSlottedPseudoElementRules):
+ (WebCore::Style::ElementRuleCollector::matchPartPseudoElementRulesForScope):
+
+ Check the scope depth limits.
+
+ * style/ElementRuleCollector.h:
+ * style/RuleSet.h:
+ (WebCore::Style::RuleSet::cascadeLayerPriorityForIdentifier const):
+ (WebCore::Style::RuleSet::cascadeLayerPriorityFor const):
+
+ Add a type alias and make it uint16_t.
+
+ * style/RuleSetBuilder.cpp:
+ (WebCore::Style::RuleSetBuilder::updateCascadeLayerPriorities):
+ * style/StyleScopeOrdinal.h:
+ (WebCore::Style::operator++):
+ (WebCore::Style::operator--):
+
+ Use int8_t. No realistic case requires more than a handful.
+
2021-11-07 Alan Bujtas <[email protected]>
[LFC][IFC] bidi boundary does not necessarily mean soft wrapping opportunity
Modified: trunk/Source/WebCore/style/ElementRuleCollector.cpp (285391 => 285392)
--- trunk/Source/WebCore/style/ElementRuleCollector.cpp 2021-11-07 18:39:07 UTC (rev 285391)
+++ trunk/Source/WebCore/style/ElementRuleCollector.cpp 2021-11-07 18:58:10 UTC (rev 285392)
@@ -286,6 +286,9 @@
MatchRequest scopeMatchRequest(&scopeAuthorRules, styleScopeOrdinal);
collectMatchingRulesForList(&scopeAuthorRules.slottedPseudoElementRules(), scopeMatchRequest);
+
+ if (styleScopeOrdinal == ScopeOrdinal::SlotLimit)
+ break;
}
}
@@ -320,6 +323,9 @@
// Element may only be exposed to styling from enclosing scopes via exportparts attributes.
if (element != &partMatchingElement && element->shadowRoot()->partMappings().isEmpty())
break;
+
+ if (styleScopeOrdinal == ScopeOrdinal::ContainingHostLimit)
+ break;
}
}
Modified: trunk/Source/WebCore/style/ElementRuleCollector.h (285391 => 285392)
--- trunk/Source/WebCore/style/ElementRuleCollector.h 2021-11-07 18:39:07 UTC (rev 285391)
+++ trunk/Source/WebCore/style/ElementRuleCollector.h 2021-11-07 18:58:10 UTC (rev 285392)
@@ -63,7 +63,7 @@
const RuleData* ruleData;
unsigned specificity;
ScopeOrdinal styleScopeOrdinal;
- unsigned cascadeLayerPriority;
+ CascadeLayerPriority cascadeLayerPriority;
};
struct MatchedProperties {
Modified: trunk/Source/WebCore/style/RuleSet.h (285391 => 285392)
--- trunk/Source/WebCore/style/RuleSet.h 2021-11-07 18:39:07 UTC (rev 285391)
+++ trunk/Source/WebCore/style/RuleSet.h 2021-11-07 18:58:10 UTC (rev 285392)
@@ -43,6 +43,8 @@
class Resolver;
class RuleSet;
+using CascadeLayerPriority = uint16_t;
+
using InvalidationRuleSetVector = Vector<RefPtr<const RuleSet>, 1>;
struct DynamicMediaQueryEvaluationChanges {
@@ -103,8 +105,8 @@
bool hasShadowPseudoElementRules() const { return !m_shadowPseudoElementRules.isEmpty(); }
bool hasHostPseudoClassRulesMatchingInShadowTree() const { return m_hasHostPseudoClassRulesMatchingInShadowTree; }
- static constexpr auto cascadeLayerPriorityForUnlayered = std::numeric_limits<unsigned>::max();
- unsigned cascadeLayerPriorityFor(const RuleData&) const;
+ static constexpr auto cascadeLayerPriorityForUnlayered = std::numeric_limits<CascadeLayerPriority>::max();
+ CascadeLayerPriority cascadeLayerPriorityFor(const RuleData&) const;
private:
friend class RuleSetBuilder;
@@ -132,11 +134,11 @@
struct CascadeLayer {
CascadeLayerName resolvedName;
CascadeLayerIdentifier parentIdentifier;
- unsigned priority { 0 };
+ CascadeLayerPriority priority { 0 };
};
CascadeLayer& cascadeLayerForIdentifier(CascadeLayerIdentifier identifier) { return m_cascadeLayers[identifier - 1]; }
const CascadeLayer& cascadeLayerForIdentifier(CascadeLayerIdentifier identifier) const { return m_cascadeLayers[identifier - 1]; }
- unsigned cascadeLayerPriorityForIdentifier(CascadeLayerIdentifier) const;
+ CascadeLayerPriority cascadeLayerPriorityForIdentifier(CascadeLayerIdentifier) const;
struct DynamicMediaQueryRules {
Vector<Ref<const MediaQuerySet>> mediaQuerySets;
@@ -193,7 +195,7 @@
return tagRules->get(key);
}
-inline unsigned RuleSet::cascadeLayerPriorityForIdentifier(CascadeLayerIdentifier identifier) const
+inline CascadeLayerPriority RuleSet::cascadeLayerPriorityForIdentifier(CascadeLayerIdentifier identifier) const
{
if (!identifier)
return cascadeLayerPriorityForUnlayered;
@@ -200,7 +202,7 @@
return cascadeLayerForIdentifier(identifier).priority;
}
-inline unsigned RuleSet::cascadeLayerPriorityFor(const RuleData& ruleData) const
+inline CascadeLayerPriority RuleSet::cascadeLayerPriorityFor(const RuleData& ruleData) const
{
if (m_cascadeLayerIdentifierForRulePosition.size() <= ruleData.position())
return cascadeLayerPriorityForUnlayered;
Modified: trunk/Source/WebCore/style/RuleSetBuilder.cpp (285391 => 285392)
--- trunk/Source/WebCore/style/RuleSetBuilder.cpp 2021-11-07 18:39:07 UTC (rev 285391)
+++ trunk/Source/WebCore/style/RuleSetBuilder.cpp 2021-11-07 18:58:10 UTC (rev 285392)
@@ -270,8 +270,10 @@
std::sort(layersInPriorityOrder.begin(), layersInPriorityOrder.end(), compare);
- for (unsigned priority = 0; priority < layerCount; ++priority)
- m_ruleSet->cascadeLayerForIdentifier(layersInPriorityOrder[priority]).priority = priority;
+ for (unsigned i = 0; i < layerCount; ++i) {
+ auto priority = std::min<unsigned>(i, RuleSet::cascadeLayerPriorityForUnlayered - 1);
+ m_ruleSet->cascadeLayerForIdentifier(layersInPriorityOrder[i]).priority = priority;
+ }
}
void RuleSetBuilder::addMutatingRulesToResolver()
Modified: trunk/Source/WebCore/style/StyleScopeOrdinal.h (285391 => 285392)
--- trunk/Source/WebCore/style/StyleScopeOrdinal.h 2021-11-07 18:39:07 UTC (rev 285391)
+++ trunk/Source/WebCore/style/StyleScopeOrdinal.h 2021-11-07 18:58:10 UTC (rev 285392)
@@ -29,23 +29,25 @@
// This is used to identify style scopes that can affect an element.
// Scopes are in tree-of-trees order. Styles from earlier scopes win over later ones (modulo !important).
-enum class ScopeOrdinal : int {
+enum class ScopeOrdinal : int8_t {
+ ContainingHostLimit = std::numeric_limits<int8_t>::min(),
ContainingHost = -1, // ::part rules and author-exposed UA pseudo classes from the host tree scope. Values less than ContainingHost indicate enclosing scopes.
Element = 0, // Normal rules in the same tree where the element is.
FirstSlot = 1, // ::slotted rules in the parent's shadow tree. Values greater than FirstSlot indicate subsequent slots in the chain.
- Shadow = std::numeric_limits<int>::max(), // :host rules in element's own shadow tree.
+ SlotLimit = std::numeric_limits<int8_t>::max() - 1,
+ Shadow = std::numeric_limits<int8_t>::max(), // :host rules in element's own shadow tree.
};
inline ScopeOrdinal& operator++(ScopeOrdinal& ordinal)
{
- ASSERT(ordinal < ScopeOrdinal::Shadow);
- return ordinal = static_cast<ScopeOrdinal>(static_cast<int>(ordinal) + 1);
+ ASSERT(ordinal < ScopeOrdinal::SlotLimit);
+ return ordinal = static_cast<ScopeOrdinal>(static_cast<int8_t>(ordinal) + 1);
}
inline ScopeOrdinal& operator--(ScopeOrdinal& ordinal)
{
- ASSERT(ordinal < ScopeOrdinal::Shadow);
- return ordinal = static_cast<ScopeOrdinal>(static_cast<int>(ordinal) - 1);
+ ASSERT(ordinal > ScopeOrdinal::ContainingHostLimit);
+ return ordinal = static_cast<ScopeOrdinal>(static_cast<int8_t>(ordinal) - 1);
}
}