mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:47:36 +00:00
LibWeb: Use StyleComputer::invalidate_rule_cache() directly everywhere
Get rid of the old, roundabout way of invalidating the rule cache by incrementing the StyleSheetList "generation". Instead, when something wants to invalidate the rule cache, just have it directly invalidate the rule cache. This makes it much easier to see what's happening anyway.
This commit is contained in:
parent
72e6bff8b8
commit
759bfbb572
6 changed files with 6 additions and 12 deletions
|
@ -85,7 +85,7 @@ void CSSImportRule::resource_did_load()
|
||||||
|
|
||||||
m_style_sheet = move(sheet);
|
m_style_sheet = move(sheet);
|
||||||
|
|
||||||
m_document->style_sheets().bump_generation();
|
m_document->style_computer().invalidate_rule_cache();
|
||||||
m_document->invalidate_style();
|
m_document->invalidate_style();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ DOM::ExceptionOr<unsigned> CSSStyleSheet::insert_rule(StringView rule, unsigned
|
||||||
|
|
||||||
if (!result.is_exception()) {
|
if (!result.is_exception()) {
|
||||||
if (m_style_sheet_list) {
|
if (m_style_sheet_list) {
|
||||||
m_style_sheet_list->bump_generation();
|
m_style_sheet_list->document().style_computer().invalidate_rule_cache();
|
||||||
m_style_sheet_list->document().invalidate_style();
|
m_style_sheet_list->document().invalidate_style();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ DOM::ExceptionOr<void> CSSStyleSheet::delete_rule(unsigned index)
|
||||||
auto result = m_rules->remove_a_css_rule(index);
|
auto result = m_rules->remove_a_css_rule(index);
|
||||||
if (!result.is_exception()) {
|
if (!result.is_exception()) {
|
||||||
if (m_style_sheet_list) {
|
if (m_style_sheet_list) {
|
||||||
m_style_sheet_list->bump_generation();
|
m_style_sheet_list->document().style_computer().invalidate_rule_cache();
|
||||||
m_style_sheet_list->document().invalidate_style();
|
m_style_sheet_list->document().invalidate_style();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1071,7 +1071,7 @@ bool PropertyDependencyNode::has_cycles()
|
||||||
|
|
||||||
void StyleComputer::build_rule_cache_if_needed() const
|
void StyleComputer::build_rule_cache_if_needed() const
|
||||||
{
|
{
|
||||||
if (m_rule_cache && m_rule_cache->generation == m_document.style_sheets().generation())
|
if (m_rule_cache)
|
||||||
return;
|
return;
|
||||||
const_cast<StyleComputer&>(*this).build_rule_cache();
|
const_cast<StyleComputer&>(*this).build_rule_cache();
|
||||||
}
|
}
|
||||||
|
@ -1146,8 +1146,6 @@ void StyleComputer::build_rule_cache()
|
||||||
dbgln(" Other: {}", m_rule_cache->other_rules.size());
|
dbgln(" Other: {}", m_rule_cache->other_rules.size());
|
||||||
dbgln(" Total: {}", num_class_rules + num_id_rules + num_tag_name_rules + m_rule_cache->other_rules.size());
|
dbgln(" Total: {}", num_class_rules + num_id_rules + num_tag_name_rules + m_rule_cache->other_rules.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_rule_cache->generation = m_document.style_sheets().generation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyleComputer::invalidate_rule_cache()
|
void StyleComputer::invalidate_rule_cache()
|
||||||
|
|
|
@ -104,7 +104,6 @@ private:
|
||||||
HashMap<FlyString, Vector<MatchingRule>> rules_by_tag_name;
|
HashMap<FlyString, Vector<MatchingRule>> rules_by_tag_name;
|
||||||
HashMap<Selector::PseudoElement, Vector<MatchingRule>> rules_by_pseudo_element;
|
HashMap<Selector::PseudoElement, Vector<MatchingRule>> rules_by_pseudo_element;
|
||||||
Vector<MatchingRule> other_rules;
|
Vector<MatchingRule> other_rules;
|
||||||
int generation { 0 };
|
|
||||||
};
|
};
|
||||||
OwnPtr<RuleCache> m_rule_cache;
|
OwnPtr<RuleCache> m_rule_cache;
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,7 +15,7 @@ void StyleSheetList::add_sheet(NonnullRefPtr<CSSStyleSheet> sheet)
|
||||||
sheet->set_style_sheet_list({}, this);
|
sheet->set_style_sheet_list({}, this);
|
||||||
m_sheets.append(move(sheet));
|
m_sheets.append(move(sheet));
|
||||||
|
|
||||||
++m_generation;
|
m_document.style_computer().invalidate_rule_cache();
|
||||||
m_document.invalidate_style();
|
m_document.invalidate_style();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ void StyleSheetList::remove_sheet(CSSStyleSheet& sheet)
|
||||||
sheet.set_style_sheet_list({}, nullptr);
|
sheet.set_style_sheet_list({}, nullptr);
|
||||||
m_sheets.remove_first_matching([&](auto& entry) { return &*entry == &sheet; });
|
m_sheets.remove_first_matching([&](auto& entry) { return &*entry == &sheet; });
|
||||||
|
|
||||||
++m_generation;
|
m_document.style_computer().invalidate_rule_cache();
|
||||||
m_document.invalidate_style();
|
m_document.invalidate_style();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,9 +43,6 @@ public:
|
||||||
|
|
||||||
bool is_supported_property_index(u32) const;
|
bool is_supported_property_index(u32) const;
|
||||||
|
|
||||||
int generation() const { return m_generation; }
|
|
||||||
void bump_generation() { ++m_generation; }
|
|
||||||
|
|
||||||
DOM::Document& document() { return m_document; }
|
DOM::Document& document() { return m_document; }
|
||||||
DOM::Document const& document() const { return m_document; }
|
DOM::Document const& document() const { return m_document; }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue