mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 03:25:13 +00:00
LibWeb: Avoid invalidation on .textContent setter no-op
When setting the textContent of an element with no children to null or the empty string, nothing happens. Even so, we were still invalidating style, layout and collections, causing pointless churn. Skipping invalidation in this case also revealed that we were missing invalidation when changing the selected state of HTMLOptionElement. This was all caught by existing tests already in-tree. :^)
This commit is contained in:
parent
8214371ad5
commit
49a7a0f378
Notes:
github-actions[bot]
2025-01-05 12:37:11 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/49a7a0f378a Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3149
3 changed files with 8 additions and 0 deletions
|
@ -202,6 +202,10 @@ void Node::set_text_content(Optional<String> const& maybe_content)
|
|||
|
||||
// If DocumentFragment or Element, string replace all with the given value within this.
|
||||
if (is<DocumentFragment>(this) || is<Element>(this)) {
|
||||
// OPTIMIZATION: Replacing nothing with nothing is a no-op. Avoid all invalidation in this case.
|
||||
if (!first_child() && content.is_empty()) {
|
||||
return;
|
||||
}
|
||||
string_replace_all(content);
|
||||
}
|
||||
|
||||
|
|
|
@ -74,6 +74,7 @@ enum class IsDescendant {
|
|||
X(HTMLIFrameElementGeometryChange) \
|
||||
X(HTMLInputElementSetChecked) \
|
||||
X(HTMLObjectElementUpdateLayoutAndChildObjects) \
|
||||
X(HTMLOptionElementSelectedChange) \
|
||||
X(HTMLSelectElementSetIsOpen) \
|
||||
X(Hover) \
|
||||
X(MediaQueryChangedMatchState) \
|
||||
|
|
|
@ -68,6 +68,9 @@ void HTMLOptionElement::set_selected(bool selected)
|
|||
|
||||
void HTMLOptionElement::set_selected_internal(bool selected)
|
||||
{
|
||||
if (m_selected != selected)
|
||||
invalidate_style(DOM::StyleInvalidationReason::HTMLOptionElementSelectedChange);
|
||||
|
||||
m_selected = selected;
|
||||
if (selected)
|
||||
m_selectedness_update_index = m_next_selectedness_update_index++;
|
||||
|
|
Loading…
Add table
Reference in a new issue