1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 18:25:06 +00:00

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. :^)
This commit is contained in:
Andreas Kling 2020-12-15 18:53:35 +01:00
parent 23f70535e2
commit 58bade25dd
3 changed files with 11 additions and 0 deletions

View file

@ -33,6 +33,8 @@ namespace Web::CSS {
StyleInvalidator::StyleInvalidator(DOM::Document& document) StyleInvalidator::StyleInvalidator(DOM::Document& document)
: m_document(document) : m_document(document)
{ {
if (!m_document.should_invalidate_styles_on_attribute_changes())
return;
auto& style_resolver = m_document.style_resolver(); auto& style_resolver = m_document.style_resolver();
m_document.for_each_in_subtree_of_type<DOM::Element>([&](auto& element) { m_document.for_each_in_subtree_of_type<DOM::Element>([&](auto& element) {
m_elements_and_matching_rules_before.set(&element, style_resolver.collect_matching_rules(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() StyleInvalidator::~StyleInvalidator()
{ {
if (!m_document.should_invalidate_styles_on_attribute_changes())
return;
auto& style_resolver = m_document.style_resolver(); auto& style_resolver = m_document.style_resolver();
m_document.for_each_in_subtree_of_type<DOM::Element>([&](auto& element) { m_document.for_each_in_subtree_of_type<DOM::Element>([&](auto& element) {
auto maybe_matching_rules_before = m_elements_and_matching_rules_before.get(&element); auto maybe_matching_rules_before = m_elements_and_matching_rules_before.get(&element);

View file

@ -61,6 +61,9 @@ public:
static NonnullRefPtr<Document> create(const URL& url = "about:blank") { return adopt(*new Document(url)); } static NonnullRefPtr<Document> create(const URL& url = "about:blank") { return adopt(*new Document(url)); }
virtual ~Document() override; 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; } void set_url(const URL& url) { m_url = url; }
URL url() const { return m_url; } URL url() const { return m_url; }
@ -283,6 +286,8 @@ private:
bool m_ready_for_post_load_tasks { false }; bool m_ready_for_post_load_tasks { false };
NonnullRefPtr<DOMImplementation> m_implementation; NonnullRefPtr<DOMImplementation> m_implementation;
bool m_should_invalidate_styles_on_attribute_changes { true };
}; };
} }

View file

@ -122,11 +122,13 @@ HTMLDocumentParser::HTMLDocumentParser(DOM::Document& document, const StringView
: m_tokenizer(input, encoding) : m_tokenizer(input, encoding)
, m_document(document) , m_document(document)
{ {
m_document->set_should_invalidate_styles_on_attribute_changes(false);
m_document->set_encoding(TextCodec::get_standardized_encoding(encoding)); m_document->set_encoding(TextCodec::get_standardized_encoding(encoding));
} }
HTMLDocumentParser::~HTMLDocumentParser() HTMLDocumentParser::~HTMLDocumentParser()
{ {
m_document->set_should_invalidate_styles_on_attribute_changes(true);
} }
void HTMLDocumentParser::run(const URL& url) void HTMLDocumentParser::run(const URL& url)