Skip to content

Commit

Permalink
Avoid traversing the FrameTree up in FrameTree::top()
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=185394

Reviewed by Chris Dumez.

Credits & Patch Authored by Chris Dumez.

Avoid traversing the FrameTree up in FrameTree::top() and rely on Frame::mainFrame() instead to get
the answer right away. There is a potential behavior change if calling FrameTree::top() on a detached
frame (it will keep return the main frame now instead of returning the frame itself). However, it
should not matter in practice as we should not be dealing with the FrameTree of a detached frame.

* Source/WebCore/page/FrameTree.cpp:
(FrameTree::top):

Canonical link: https://commits.webkit.org/273230@main
  • Loading branch information
Ahmad-S792 authored and cdumez committed Jan 19, 2024
1 parent 10afd1e commit 80993fd
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Source/WebCore/page/FrameTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,8 @@ Frame* FrameTree::deepLastChild() const

Frame& FrameTree::top() const
{
auto* frame = &m_thisFrame;
for (auto* parent = &m_thisFrame; parent; parent = parent->tree().parent())
frame = parent;
return *frame;
ASSERT(m_thisFrame.isMainFrame() || m_thisFrame.tree().parent());
return m_thisFrame.mainFrame();
}

unsigned FrameTree::depth() const
Expand Down

0 comments on commit 80993fd

Please sign in to comment.