From 58bade25dd36c9eded4c8f1464f7032793f21b1c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 15 Dec 2020 18:53:35 +0100 Subject: [PATCH] LibWeb: Add hack to disable StyleInvalidator while parsing document Running a StyleInvalidator for every attribute set in a new document was making it impossible to load larger sites. :^) --- Libraries/LibWeb/CSS/StyleInvalidator.cpp | 4 ++++ Libraries/LibWeb/DOM/Document.h | 5 +++++ Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp | 2 ++ 3 files changed, 11 insertions(+) diff --git a/Libraries/LibWeb/CSS/StyleInvalidator.cpp b/Libraries/LibWeb/CSS/StyleInvalidator.cpp index 0dd48840d5..bf5f15c332 100644 --- a/Libraries/LibWeb/CSS/StyleInvalidator.cpp +++ b/Libraries/LibWeb/CSS/StyleInvalidator.cpp @@ -33,6 +33,8 @@ namespace Web::CSS { StyleInvalidator::StyleInvalidator(DOM::Document& document) : m_document(document) { + if (!m_document.should_invalidate_styles_on_attribute_changes()) + return; auto& style_resolver = m_document.style_resolver(); m_document.for_each_in_subtree_of_type([&](auto& element) { m_elements_and_matching_rules_before.set(&element, style_resolver.collect_matching_rules(element)); @@ -42,6 +44,8 @@ StyleInvalidator::StyleInvalidator(DOM::Document& document) StyleInvalidator::~StyleInvalidator() { + if (!m_document.should_invalidate_styles_on_attribute_changes()) + return; auto& style_resolver = m_document.style_resolver(); m_document.for_each_in_subtree_of_type([&](auto& element) { auto maybe_matching_rules_before = m_elements_and_matching_rules_before.get(&element); diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index 0dba6aed7b..8434beeb8e 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/Libraries/LibWeb/DOM/Document.h @@ -61,6 +61,9 @@ public: static NonnullRefPtr create(const URL& url = "about:blank") { return adopt(*new Document(url)); } virtual ~Document() override; + bool should_invalidate_styles_on_attribute_changes() const { return m_should_invalidate_styles_on_attribute_changes; } + void set_should_invalidate_styles_on_attribute_changes(bool b) { m_should_invalidate_styles_on_attribute_changes = b; } + void set_url(const URL& url) { m_url = url; } URL url() const { return m_url; } @@ -283,6 +286,8 @@ private: bool m_ready_for_post_load_tasks { false }; NonnullRefPtr m_implementation; + + bool m_should_invalidate_styles_on_attribute_changes { true }; }; } diff --git a/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp b/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp index 1927274a73..417effea75 100644 --- a/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp +++ b/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp @@ -122,11 +122,13 @@ HTMLDocumentParser::HTMLDocumentParser(DOM::Document& document, const StringView : m_tokenizer(input, encoding) , m_document(document) { + m_document->set_should_invalidate_styles_on_attribute_changes(false); m_document->set_encoding(TextCodec::get_standardized_encoding(encoding)); } HTMLDocumentParser::~HTMLDocumentParser() { + m_document->set_should_invalidate_styles_on_attribute_changes(true); } void HTMLDocumentParser::run(const URL& url)