Skip to content

Commit

Permalink
Reduce the amount of SVGElement::updateRelativeLengthsInformation() c…
Browse files Browse the repository at this point in the history
…alls

https://bugs.webkit.org/show_bug.cgi?id=260971

Reviewed by Ryosuke Niwa.

Reduce the amount of SVGElement::updateRelativeLengthsInformation() calls.

In SVGElement::removedFromAncestor(), if `removalType.disconnectedFromDocument`
was true, we would call `updateRelativeLengthsInformation(false, *this)` to remove
the element from m_elementsWithRelativeLengths and from our ancestor's map.

However, when SVGElement::removedFromAncestor() gets called, we know that
the element either doesn't have a parent or that it's parent is not connected
(I added an assertion to this effect). As a result, recursively calling
`updateRelativeLengthsInformation(false, element)` on the ancestors had no
effect, since the function would early return at the `!isConnected()` check.

As a result, it is sufficient to clear m_elementsWithRelativeLengths in
SVGElement::removedFromAncestor(), without calling
`updateRelativeLengthsInformation(false, *this)` or worrying about the
ancestors.

* Source/WebCore/svg/SVGElement.cpp:
(WebCore::SVGElement::removedFromAncestor):

Canonical link: https://commits.webkit.org/267517@main
  • Loading branch information
cdumez committed Aug 31, 2023
1 parent 3b214fe commit fab9172
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Source/WebCore/svg/SVGElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ void SVGElement::reportAttributeParsingError(SVGParsingError error, const Qualif

void SVGElement::removedFromAncestor(RemovalType removalType, ContainerNode& oldParentOfRemovedTree)
{
if (removalType.disconnectedFromDocument)
updateRelativeLengthsInformation(false, *this);
if (removalType.disconnectedFromDocument) {
ASSERT(!parentNode() || !parentNode()->isConnected());
m_elementsWithRelativeLengths.clear();
}

StyledElement::removedFromAncestor(removalType, oldParentOfRemovedTree);

Expand Down

0 comments on commit fab9172

Please sign in to comment.