From 759bfbb572db2c0389744965cc654e3e762a8172 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 14 Mar 2022 20:31:57 +0100 Subject: [PATCH] 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. --- Userland/Libraries/LibWeb/CSS/CSSImportRule.cpp | 2 +- Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp | 4 ++-- Userland/Libraries/LibWeb/CSS/StyleComputer.cpp | 4 +--- Userland/Libraries/LibWeb/CSS/StyleComputer.h | 1 - Userland/Libraries/LibWeb/CSS/StyleSheetList.cpp | 4 ++-- Userland/Libraries/LibWeb/CSS/StyleSheetList.h | 3 --- 6 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/CSSImportRule.cpp b/Userland/Libraries/LibWeb/CSS/CSSImportRule.cpp index 6789443b5f8..c088d6030dc 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSImportRule.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSImportRule.cpp @@ -85,7 +85,7 @@ void CSSImportRule::resource_did_load() m_style_sheet = move(sheet); - m_document->style_sheets().bump_generation(); + m_document->style_computer().invalidate_rule_cache(); m_document->invalidate_style(); } diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp index 7ec8a5248e8..b44a87eb7ec 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp @@ -42,7 +42,7 @@ DOM::ExceptionOr CSSStyleSheet::insert_rule(StringView rule, unsigned if (!result.is_exception()) { 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(); } } @@ -61,7 +61,7 @@ DOM::ExceptionOr CSSStyleSheet::delete_rule(unsigned index) auto result = m_rules->remove_a_css_rule(index); if (!result.is_exception()) { 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(); } } diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index cd4561ee5d2..01425724abf 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -1071,7 +1071,7 @@ bool PropertyDependencyNode::has_cycles() 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; const_cast(*this).build_rule_cache(); } @@ -1146,8 +1146,6 @@ void StyleComputer::build_rule_cache() 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()); } - - m_rule_cache->generation = m_document.style_sheets().generation(); } void StyleComputer::invalidate_rule_cache() diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.h b/Userland/Libraries/LibWeb/CSS/StyleComputer.h index 6a1e3976a7d..2c688b3cc2d 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.h +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.h @@ -104,7 +104,6 @@ private: HashMap> rules_by_tag_name; HashMap> rules_by_pseudo_element; Vector other_rules; - int generation { 0 }; }; OwnPtr m_rule_cache; }; diff --git a/Userland/Libraries/LibWeb/CSS/StyleSheetList.cpp b/Userland/Libraries/LibWeb/CSS/StyleSheetList.cpp index 23d6dd96d60..a43ab4711a9 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleSheetList.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleSheetList.cpp @@ -15,7 +15,7 @@ void StyleSheetList::add_sheet(NonnullRefPtr sheet) sheet->set_style_sheet_list({}, this); m_sheets.append(move(sheet)); - ++m_generation; + m_document.style_computer().invalidate_rule_cache(); m_document.invalidate_style(); } @@ -24,7 +24,7 @@ void StyleSheetList::remove_sheet(CSSStyleSheet& sheet) sheet.set_style_sheet_list({}, nullptr); m_sheets.remove_first_matching([&](auto& entry) { return &*entry == &sheet; }); - ++m_generation; + m_document.style_computer().invalidate_rule_cache(); m_document.invalidate_style(); } diff --git a/Userland/Libraries/LibWeb/CSS/StyleSheetList.h b/Userland/Libraries/LibWeb/CSS/StyleSheetList.h index 70eb9157387..0fe931becee 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleSheetList.h +++ b/Userland/Libraries/LibWeb/CSS/StyleSheetList.h @@ -43,9 +43,6 @@ public: 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 const& document() const { return m_document; }