commit 454911cd834f085439203f6e66a285ceaeeeac40
parent 37d30808aee22cfab5b51422101b0750b4e87071
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date: Fri, 3 Oct 2025 08:37:06 +0000
Bug 1948933 - Avoid looking up insertion point when turning something into display: none. r=layout-reviewers,tnikkel
Seems worth doing, to avoid some potentially quadratic cases when
switching a lot of elements to be display: none.
Differential Revision: https://phabricator.services.mozilla.com/D267371
Diffstat:
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp
@@ -8475,9 +8475,13 @@ void nsCSSFrameConstructor::RecreateFramesForContent(
MOZ_ASSERT(aContent->GetParentNode());
const bool didReconstruct =
ContentWillBeRemoved(aContent, REMOVE_FOR_RECONSTRUCTION);
-
- if (!didReconstruct) {
- if (aInsertionKind == InsertionKind::Async && aContent->IsElement()) {
+ if (didReconstruct) {
+ // If ContentWillBeRemoved triggered reconstruction, then we don't need to
+ // do anything else because the frames will already have been built.
+ return;
+ }
+ if (aContent->IsElement()) {
+ if (aInsertionKind == InsertionKind::Async) {
// FIXME(emilio, bug 1397239): There's nothing removing the frame state
// for elements that go away before we come back to the frame
// constructor.
@@ -8487,14 +8491,16 @@ void nsCSSFrameConstructor::RecreateFramesForContent(
// construction to apply to all elements first.
RestyleManager()->PostRestyleEvent(aContent->AsElement(), RestyleHint{0},
nsChangeHint_ReconstructFrame);
- } else {
- // Now, recreate the frames associated with this content object. If
- // ContentWillBeRemoved triggered reconstruction, then we don't need to do
- // this because the frames will already have been built.
- ContentRangeInserted(aContent, aContent->GetNextSibling(),
- aInsertionKind);
+ return;
+ }
+ // If we're display: none, there's no point on trying to find an insertion
+ // point, we're done.
+ if (Servo_Element_IsDisplayNone(aContent->AsElement())) {
+ return;
}
}
+ // Now, recreate the frames associated with this content object.
+ ContentRangeInserted(aContent, aContent->GetNextSibling(), aInsertionKind);
}
bool nsCSSFrameConstructor::DestroyFramesFor(nsIContent* aContent) {