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:
parent
23f70535e2
commit
58bade25dd
Notes:
sideshowbarker
2024-07-19 00:48:43 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/58bade25dd3
3 changed files with 11 additions and 0 deletions
|
@ -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<DOM::Element>([&](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<DOM::Element>([&](auto& element) {
|
||||
auto maybe_matching_rules_before = m_elements_and_matching_rules_before.get(&element);
|
||||
|
|
|
@ -61,6 +61,9 @@ public:
|
|||
static NonnullRefPtr<Document> 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<DOMImplementation> m_implementation;
|
||||
|
||||
bool m_should_invalidate_styles_on_attribute_changes { true };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue