Diff
Modified: trunk/Source/WebCore/ChangeLog (287478 => 287479)
--- trunk/Source/WebCore/ChangeLog 2021-12-29 16:33:42 UTC (rev 287478)
+++ trunk/Source/WebCore/ChangeLog 2021-12-29 16:35:22 UTC (rev 287479)
@@ -1,3 +1,35 @@
+2021-12-29 Antti Koivisto <[email protected]>
+
+ Make MatchElement in RuleFeature non-optional
+ https://bugs.webkit.org/show_bug.cgi?id=234738
+
+ Reviewed by Sam Weinig.
+
+ Split no-MatchElement case into a separate RuleAndSelector struct.
+
+ Also make MediaQueryCollector collect whole StyleRules instead of using RuleFeature/RuleAndSelector for simplicity
+ and better logic. Media queries always affect all of a StyleRule, not some invidiual selectors.
+
+ * style/RuleFeature.cpp:
+ (WebCore::Style::RuleAndSelector::RuleAndSelector):
+ (WebCore::Style::RuleFeature::RuleFeature):
+ * style/RuleFeature.h:
+ (WebCore::Style::RuleFeatureWithInvalidationSelector::RuleFeatureWithInvalidationSelector):
+ * style/RuleSet.cpp:
+ (WebCore::Style::RuleSet::evaluateDynamicMediaQueryRules):
+
+ Use RuleSetBuilder to build the media query invalidation ruleset. It also does shrink-to-fit for us.
+
+ * style/RuleSet.h:
+ (WebCore::Style::RuleSet::DynamicMediaQueryRules::shrinkToFit):
+ * style/RuleSetBuilder.cpp:
+ (WebCore::Style::RuleSetBuilder::MediaQueryCollector::pop):
+ (WebCore::Style::RuleSetBuilder::MediaQueryCollector::addRuleIfNeeded):
+ * style/RuleSetBuilder.h:
+ * style/StyleScopeRuleSets.cpp:
+ (WebCore::Style::makeRuleSet):
+ (WebCore::Style::ensureInvalidationRuleSets):
+
2021-12-29 Alan Bujtas <[email protected]>
[LFC][IFC] Collapsed trailing whitespace may introduce stray inline box
Modified: trunk/Source/WebCore/style/RuleFeature.cpp (287478 => 287479)
--- trunk/Source/WebCore/style/RuleFeature.cpp 2021-12-29 16:33:42 UTC (rev 287478)
+++ trunk/Source/WebCore/style/RuleFeature.cpp 2021-12-29 16:35:22 UTC (rev 287479)
@@ -74,16 +74,22 @@
}
}
-RuleFeature::RuleFeature(const RuleData& ruleData, std::optional<MatchElement> matchElement)
+RuleAndSelector::RuleAndSelector(const RuleData& ruleData)
: styleRule(&ruleData.styleRule())
, selectorIndex(ruleData.selectorIndex())
, selectorListIndex(ruleData.selectorListIndex())
- , matchElement(matchElement)
{
ASSERT(selectorIndex == ruleData.selectorIndex());
ASSERT(selectorListIndex == ruleData.selectorListIndex());
}
+
+RuleFeature::RuleFeature(const RuleData& ruleData, MatchElement matchElement)
+ : RuleAndSelector(ruleData)
+ , matchElement(matchElement)
+{
+}
+
static MatchElement computeNextMatchElement(MatchElement matchElement, CSSSelector::RelationType relation)
{
if (isHasPseudoClassMatchElement(matchElement))
Modified: trunk/Source/WebCore/style/RuleFeature.h (287478 => 287479)
--- trunk/Source/WebCore/style/RuleFeature.h 2021-12-29 16:33:42 UTC (rev 287478)
+++ trunk/Source/WebCore/style/RuleFeature.h 2021-12-29 16:35:22 UTC (rev 287479)
@@ -55,24 +55,32 @@
};
constexpr unsigned matchElementCount = static_cast<unsigned>(MatchElement::Host) + 1;
-struct RuleFeature {
- RuleFeature(const RuleData&, std::optional<MatchElement> = std::nullopt);
+// For MSVC.
+#pragma pack(push, 4)
+struct RuleAndSelector {
+ RuleAndSelector(const RuleData&);
RefPtr<const StyleRule> styleRule;
uint16_t selectorIndex; // Keep in sync with RuleData's selectorIndex size.
uint16_t selectorListIndex; // Keep in sync with RuleData's selectorListIndex size.
- std::optional<MatchElement> matchElement { };
};
+
+struct RuleFeature : public RuleAndSelector {
+ RuleFeature(const RuleData&, MatchElement);
+
+ MatchElement matchElement;
+};
static_assert(sizeof(RuleFeature) <= 16, "RuleFeature is a frquently alocated object. Keep it small.");
struct RuleFeatureWithInvalidationSelector : public RuleFeature {
- RuleFeatureWithInvalidationSelector(const RuleData& data, std::optional<MatchElement> matchElement = std::nullopt, const CSSSelector* invalidationSelector = nullptr)
- : RuleFeature(data, WTFMove(matchElement))
+ RuleFeatureWithInvalidationSelector(const RuleData& data, MatchElement matchElement, const CSSSelector* invalidationSelector = nullptr)
+ : RuleFeature(data, matchElement)
, invalidationSelector(invalidationSelector)
{ }
const CSSSelector* invalidationSelector { nullptr };
};
+#pragma pack(pop)
using PseudoClassInvalidationKey = std::tuple<unsigned, uint8_t, AtomString>;
@@ -94,8 +102,8 @@
HashSet<AtomString> attributeCanonicalLocalNamesInRules;
HashSet<AtomString> attributeLocalNamesInRules;
HashSet<AtomString> contentAttributeNamesInRules;
- RuleFeatureVector siblingRules;
- RuleFeatureVector uncommonAttributeRules;
+ Vector<RuleAndSelector> siblingRules;
+ Vector<RuleAndSelector> uncommonAttributeRules;
HashMap<AtomString, std::unique_ptr<RuleFeatureVector>> tagRules;
HashMap<AtomString, std::unique_ptr<RuleFeatureVector>> idRules;
Modified: trunk/Source/WebCore/style/RuleSet.cpp (287478 => 287479)
--- trunk/Source/WebCore/style/RuleSet.cpp 2021-12-29 16:33:42 UTC (rev 287478)
+++ trunk/Source/WebCore/style/RuleSet.cpp 2021-12-29 16:35:22 UTC (rev 287479)
@@ -35,6 +35,7 @@
#include "CSSSelectorList.h"
#include "HTMLNames.h"
#include "MediaQueryEvaluator.h"
+#include "RuleSetBuilder.h"
#include "SecurityOrigin.h"
#include "SelectorChecker.h"
#include "SelectorFilter.h"
@@ -318,11 +319,11 @@
auto& ruleSet = m_mediaQueryInvalidationRuleSetCache.ensure(collectedChanges.changedQueryIndexes, [&] {
auto ruleSet = RuleSet::create();
- for (auto* featureVector : collectedChanges.ruleFeatures) {
- for (auto& feature : *featureVector)
- ruleSet->addRule(*feature.styleRule, feature.selectorIndex, feature.selectorListIndex);
+ RuleSetBuilder builder(ruleSet, MediaQueryEvaluator(true));
+ for (auto* rules : collectedChanges.affectedRules) {
+ for (auto& rule : *rules)
+ builder.addStyleRule(rule);
}
- ruleSet->shrinkToFit();
return ruleSet;
}).iterator->value;
@@ -357,7 +358,7 @@
affectedRulePositionsAndResults.add(position, result);
collectedChanges.changedQueryIndexes.append(i);
- collectedChanges.ruleFeatures.append(&dynamicRules.ruleFeatures);
+ collectedChanges.affectedRules.append(&dynamicRules.affectedRules);
}
}
Modified: trunk/Source/WebCore/style/RuleSet.h (287478 => 287479)
--- trunk/Source/WebCore/style/RuleSet.h 2021-12-29 16:33:42 UTC (rev 287478)
+++ trunk/Source/WebCore/style/RuleSet.h 2021-12-29 16:35:22 UTC (rev 287479)
@@ -126,7 +126,7 @@
struct CollectedMediaQueryChanges {
bool requiredFullReset { false };
Vector<size_t> changedQueryIndexes { };
- Vector<RuleFeatureVector*> ruleFeatures { };
+ Vector<Vector<Ref<const StyleRule>>*> affectedRules { };
};
CollectedMediaQueryChanges evaluateDynamicMediaQueryRules(const MediaQueryEvaluator&, size_t startIndex);
@@ -144,7 +144,7 @@
struct DynamicMediaQueryRules {
Vector<Ref<const MediaQuerySet>> mediaQuerySets;
Vector<size_t> affectedRulePositions;
- RuleFeatureVector ruleFeatures;
+ Vector<Ref<const StyleRule>> affectedRules;
bool requiresFullReset { false };
bool result { true };
@@ -152,7 +152,7 @@
{
mediaQuerySets.shrinkToFit();
affectedRulePositions.shrinkToFit();
- ruleFeatures.shrinkToFit();
+ affectedRules.shrinkToFit();
}
};
Modified: trunk/Source/WebCore/style/RuleSetBuilder.cpp (287478 => 287479)
--- trunk/Source/WebCore/style/RuleSetBuilder.cpp 2021-12-29 16:33:42 UTC (rev 287478)
+++ trunk/Source/WebCore/style/RuleSetBuilder.cpp 2021-12-29 16:35:22 UTC (rev 287479)
@@ -371,8 +371,7 @@
if (collectDynamic) {
rules.affectedRulePositions.appendVector(dynamicContextStack.last().affectedRulePositions);
- rules.ruleFeatures = WTFMove(dynamicContextStack.last().ruleFeatures);
- rules.ruleFeatures.shrinkToFit();
+ rules.affectedRules = copyToVector(dynamicContextStack.last().affectedRules);
} else
rules.requiresFullReset = true;
@@ -389,7 +388,7 @@
auto& context = dynamicContextStack.last();
context.affectedRulePositions.append(ruleData.position());
- context.ruleFeatures.append({ ruleData });
+ context.affectedRules.add(ruleData.styleRule());
}
}
Modified: trunk/Source/WebCore/style/RuleSetBuilder.h (287478 => 287479)
--- trunk/Source/WebCore/style/RuleSetBuilder.h 2021-12-29 16:33:42 UTC (rev 287478)
+++ trunk/Source/WebCore/style/RuleSetBuilder.h 2021-12-29 16:35:22 UTC (rev 287479)
@@ -33,6 +33,7 @@
~RuleSetBuilder();
void addRulesFromSheet(const StyleSheetContents&, const MediaQuerySet* sheetQuery = nullptr);
+ void addStyleRule(const StyleRule&);
private:
RuleSetBuilder(const MediaQueryEvaluator&);
@@ -39,7 +40,6 @@
void addRulesFromSheetContents(const StyleSheetContents&);
void addChildRules(const Vector<RefPtr<StyleRuleBase>>&);
- void addStyleRule(const StyleRule&);
void disallowDynamicMediaQueryEvaluationIfNeeded();
void registerLayers(const Vector<CascadeLayerName>&);
@@ -58,7 +58,7 @@
struct DynamicContext {
Ref<const MediaQuerySet> set;
Vector<size_t> affectedRulePositions { };
- RuleFeatureVector ruleFeatures { };
+ HashSet<Ref<const StyleRule>> affectedRules { };
};
Vector<DynamicContext> dynamicContextStack { };
Modified: trunk/Source/WebCore/style/StyleScopeRuleSets.cpp (287478 => 287479)
--- trunk/Source/WebCore/style/StyleScopeRuleSets.cpp 2021-12-29 16:33:42 UTC (rev 287478)
+++ trunk/Source/WebCore/style/StyleScopeRuleSets.cpp 2021-12-29 16:35:22 UTC (rev 287479)
@@ -127,7 +127,8 @@
}
}
-static RefPtr<RuleSet> makeRuleSet(const RuleFeatureVector& rules)
+template<typename Rules>
+RefPtr<RuleSet> makeRuleSet(const Rules& rules)
{
size_t size = rules.size();
if (!size)
@@ -242,8 +243,7 @@
std::array<RefPtr<RuleSet>, matchElementCount> matchElementArray;
std::array<Vector<const CSSSelector*>, matchElementCount> invalidationSelectorArray;
for (auto& feature : *features) {
- RELEASE_ASSERT(feature.matchElement);
- auto arrayIndex = static_cast<unsigned>(*feature.matchElement);
+ auto arrayIndex = static_cast<unsigned>(feature.matchElement);
RELEASE_ASSERT(arrayIndex < matchElementArray.size());
auto& ruleSet = matchElementArray[arrayIndex];