Commit 93e97597 authored by Naina Raisinghani's avatar Naina Raisinghani Committed by Commit Bot

Move has_before_or_after_ from CSSLazyParsingState to CSSLazyPropertyParserImpl

This patches moves the bool maintaining state about the prelude of the
block we are parsing (whether or not the prelude include a
::{before,after}) from CSSLazyParsingState to CSLazyPropertyParserImpl.

This is as we have one CSSLazyParsingState per stylesheet, making this 
the incorrect place to maintain the flag. Before this patch if even one 
block in the stylesheet had ::{before,after} we would lazily parse all 
blocks in the stylesheet if the other conditions in 
CSSLazyPropertyparserImpl::parseProperties was met. 

Since each block gets an  instance of the CSSLazyPropertyParser we 
maintain the information there instead. The drawback to this is 
increased memory use. There is a CSSLazyPropertyParser per declaration 
list, so that adds 1 byte of memory for a stylesheet with N deferred lists. 
However N will usually be small as can be seen in histograms 
tracked under Style.TotalLazyRules

Bug: 642722
Change-Id: Ief6272dd2ae24a31479d9f0c072c1562632a49c1
Reviewed-on: https://chromium-review.googlesource.com/686196
Commit-Queue: Darren Shen <shend@chromium.org>
Reviewed-by: default avatarCharlie Harrison <csharrison@chromium.org>
Reviewed-by: default avatarRune Lillesveen <rune@opera.com>
Cr-Commit-Position: refs/heads/master@{#504892}
parent 6c499c0a
...@@ -454,7 +454,7 @@ InvalidationSet* RuleFeatureSet::InvalidationSetForSimpleSelector( ...@@ -454,7 +454,7 @@ InvalidationSet* RuleFeatureSet::InvalidationSetForSimpleSelector(
return nullptr; return nullptr;
} }
void RuleFeatureSet::UpdateInvalidationSets(const RuleData& rule_data) { void RuleFeatureSet::UpdateInvalidationSets(RuleData& rule_data) {
// Given a rule, update the descendant invalidation sets for the features // Given a rule, update the descendant invalidation sets for the features
// found in its selector. The first step is to extract the features from the // found in its selector. The first step is to extract the features from the
// rightmost compound selector (extractInvalidationSetFeaturesFromCompound). // rightmost compound selector (extractInvalidationSetFeaturesFromCompound).
...@@ -479,7 +479,7 @@ void RuleFeatureSet::UpdateInvalidationSets(const RuleData& rule_data) { ...@@ -479,7 +479,7 @@ void RuleFeatureSet::UpdateInvalidationSets(const RuleData& rule_data) {
AddFeaturesToInvalidationSet(EnsureNthInvalidationSet(), features); AddFeaturesToInvalidationSet(EnsureNthInvalidationSet(), features);
if (features.has_before_or_after) { if (features.has_before_or_after) {
if (rule_data.Rule()->LazyParser()) if (rule_data.Rule()->LazyParser())
rule_data.Rule()->LazyParser()->LazyState()->SetHasBeforeOrAfter(); rule_data.Rule()->LazyParser()->SetHasBeforeOrAfter();
UpdateInvalidationSetsForContentAttribute( UpdateInvalidationSetsForContentAttribute(
rule_data.Rule()->ParsedProperties()); rule_data.Rule()->ParsedProperties());
} }
...@@ -806,7 +806,7 @@ void RuleFeatureSet::AddFeaturesToInvalidationSets( ...@@ -806,7 +806,7 @@ void RuleFeatureSet::AddFeaturesToInvalidationSets(
} }
RuleFeatureSet::SelectorPreMatch RuleFeatureSet::CollectFeaturesFromRuleData( RuleFeatureSet::SelectorPreMatch RuleFeatureSet::CollectFeaturesFromRuleData(
const RuleData& rule_data) { RuleData& rule_data) {
CHECK(is_alive_); CHECK(is_alive_);
FeatureMetadata metadata; FeatureMetadata metadata;
if (CollectFeaturesFromSelector(rule_data.Selector(), metadata) == if (CollectFeaturesFromSelector(rule_data.Selector(), metadata) ==
......
...@@ -53,7 +53,7 @@ class CORE_EXPORT RuleFeatureSet { ...@@ -53,7 +53,7 @@ class CORE_EXPORT RuleFeatureSet {
enum SelectorPreMatch { kSelectorNeverMatches, kSelectorMayMatch }; enum SelectorPreMatch { kSelectorNeverMatches, kSelectorMayMatch };
SelectorPreMatch CollectFeaturesFromRuleData(const RuleData&); SelectorPreMatch CollectFeaturesFromRuleData(RuleData&);
void UpdateInvalidationSetsForContentAttribute(const StylePropertySet*); void UpdateInvalidationSetsForContentAttribute(const StylePropertySet*);
bool UsesFirstLineRules() const { return metadata_.uses_first_line_rules; } bool UsesFirstLineRules() const { return metadata_.uses_first_line_rules; }
...@@ -178,7 +178,7 @@ class CORE_EXPORT RuleFeatureSet { ...@@ -178,7 +178,7 @@ class CORE_EXPORT RuleFeatureSet {
DescendantInvalidationSet& EnsureNthInvalidationSet(); DescendantInvalidationSet& EnsureNthInvalidationSet();
DescendantInvalidationSet& EnsureTypeRuleInvalidationSet(); DescendantInvalidationSet& EnsureTypeRuleInvalidationSet();
void UpdateInvalidationSets(const RuleData&); void UpdateInvalidationSets(RuleData&);
struct InvalidationSetFeatures { struct InvalidationSetFeatures {
DISALLOW_NEW(); DISALLOW_NEW();
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
namespace blink { namespace blink {
class CSSStyleDeclaration; class CSSStyleDeclaration;
class CSSLazyParsingState;
class ImmutableStylePropertySet; class ImmutableStylePropertySet;
class MutableStylePropertySet; class MutableStylePropertySet;
class PropertyRegistry; class PropertyRegistry;
...@@ -166,7 +165,7 @@ class CSSLazyPropertyParser ...@@ -166,7 +165,7 @@ class CSSLazyPropertyParser
CSSLazyPropertyParser() {} CSSLazyPropertyParser() {}
virtual ~CSSLazyPropertyParser() {} virtual ~CSSLazyPropertyParser() {}
virtual StylePropertySet* ParseProperties() = 0; virtual StylePropertySet* ParseProperties() = 0;
virtual CSSLazyParsingState* LazyState() const = 0; virtual void SetHasBeforeOrAfter() = 0;
DECLARE_VIRTUAL_TRACE(); DECLARE_VIRTUAL_TRACE();
}; };
......
...@@ -110,9 +110,7 @@ class CORE_EXPORT StyleRule : public StyleRuleBase { ...@@ -110,9 +110,7 @@ class CORE_EXPORT StyleRule : public StyleRuleBase {
const StylePropertySet& Properties() const; const StylePropertySet& Properties() const;
const StylePropertySet* ParsedProperties() const { return properties_; } const StylePropertySet* ParsedProperties() const { return properties_; }
MutableStylePropertySet& MutableProperties(); MutableStylePropertySet& MutableProperties();
const CSSLazyPropertyParser* LazyParser() const { CSSLazyPropertyParser* LazyParser() { return lazy_property_parser_.Get(); }
return lazy_property_parser_.Get();
}
void WrapperAdoptSelectorList(CSSSelectorList selectors) { void WrapperAdoptSelectorList(CSSSelectorList selectors) {
selector_list_ = std::move(selectors); selector_list_ = std::move(selectors);
......
...@@ -33,9 +33,6 @@ class CSSLazyParsingState ...@@ -33,9 +33,6 @@ class CSSLazyParsingState
// know the total number of style rules that deferred parsing. // know the total number of style rules that deferred parsing.
void FinishInitialParsing(); void FinishInitialParsing();
void SetHasBeforeOrAfter() { has_before_or_after = true; }
bool HasBeforeOrAfter() { return has_before_or_after; }
// Helper method used to bump total_style_rules_. // Helper method used to bump total_style_rules_.
CSSLazyPropertyParserImpl* CreateLazyParser(const CSSParserTokenRange& block); CSSLazyPropertyParserImpl* CreateLazyParser(const CSSParserTokenRange& block);
...@@ -90,10 +87,6 @@ class CSSLazyParsingState ...@@ -90,10 +87,6 @@ class CSSLazyParsingState
int usage_; int usage_;
// Used to enable lazy parsing for content attributes inside ::before/::after
// blocks
bool has_before_or_after = false;
// Whether or not use counting is enabled for parsing. This will usually be // Whether or not use counting is enabled for parsing. This will usually be
// true, except for when stylesheets with @imports are removed from the page. // true, except for when stylesheets with @imports are removed from the page.
// See StyleRuleImport::setCSSStyleSheet. // See StyleRuleImport::setCSSStyleSheet.
......
...@@ -24,8 +24,8 @@ StylePropertySet* CSSLazyPropertyParserImpl::ParseProperties() { ...@@ -24,8 +24,8 @@ StylePropertySet* CSSLazyPropertyParserImpl::ParseProperties() {
StylePropertySet* property_set = StylePropertySet* property_set =
CSSParserImpl::ParseDeclarationListForLazyStyle(tokens_, CSSParserImpl::ParseDeclarationListForLazyStyle(tokens_,
lazy_state_->Context()); lazy_state_->Context());
if (property_set->FindPropertyIndex(CSSPropertyContent) != -1 && if (has_before_or_after_ && lazy_state_->HasRuleSet() &&
lazy_state_->HasBeforeOrAfter() && lazy_state_->HasRuleSet()) { property_set->FindPropertyIndex(CSSPropertyContent) != -1) {
lazy_state_->GetRuleSet().UpdateInvalidationSetsForContentAttribute( lazy_state_->GetRuleSet().UpdateInvalidationSetsForContentAttribute(
property_set); property_set);
lazy_state_->GetStyleEngine().MarkGlobalRuleSetDirty(); lazy_state_->GetStyleEngine().MarkGlobalRuleSetDirty();
......
...@@ -21,7 +21,7 @@ class CSSLazyPropertyParserImpl : public CSSLazyPropertyParser { ...@@ -21,7 +21,7 @@ class CSSLazyPropertyParserImpl : public CSSLazyPropertyParser {
// CSSLazyPropertyParser: // CSSLazyPropertyParser:
StylePropertySet* ParseProperties() override; StylePropertySet* ParseProperties() override;
CSSLazyParsingState* LazyState() const override { return lazy_state_.Get(); } void SetHasBeforeOrAfter() override { has_before_or_after_ = true; }
DEFINE_INLINE_TRACE() { DEFINE_INLINE_TRACE() {
visitor->Trace(lazy_state_); visitor->Trace(lazy_state_);
...@@ -31,6 +31,7 @@ class CSSLazyPropertyParserImpl : public CSSLazyPropertyParser { ...@@ -31,6 +31,7 @@ class CSSLazyPropertyParserImpl : public CSSLazyPropertyParser {
private: private:
Vector<CSSParserToken> tokens_; Vector<CSSParserToken> tokens_;
Member<CSSLazyParsingState> lazy_state_; Member<CSSLazyParsingState> lazy_state_;
bool has_before_or_after_ = false;
}; };
} // namespace blink } // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment