[webkit-changes] [WebKit/WebKit] f5e6dd: Avoid tree traversal in FrameSelection::nodeWillBe...

Ryosuke Niwa noreply at github.com
Wed Mar 27 20:14:10 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: f5e6dd1893d0ba8146411e4e62891fd8f6056eb5
      https://github.com/WebKit/WebKit/commit/f5e6dd1893d0ba8146411e4e62891fd8f6056eb5
  Author: Ryosuke Niwa <rniwa at webkit.org>
  Date:   2024-03-27 (Wed, 27 Mar 2024)

  Changed paths:
    M Source/WebCore/dom/Node.cpp
    M Source/WebCore/dom/Node.h
    M Source/WebCore/editing/FrameSelection.cpp
    M Source/WebCore/editing/FrameSelection.h

  Log Message:
  -----------
  Avoid tree traversal in FrameSelection::nodeWillBeRemoved in most cases
https://bugs.webkit.org/show_bug.cgi?id=271748

Reviewed by Wenson Hsieh and Yusuke Suzuki.

This PR introduces a new node flag, StateFlag::ContainsSelectionEndPoint, which indicates whether
a given node contains a selection end point (start, end, base, extent, focus, or anchor), and uses
it to avoid tree walks in FrameSelection::nodeWillBeRemoved.

* Source/WebCore/dom/Node.cpp:
(WebCore::Node::insertedIntoAncestor): Assert that the node flag isn't set when a node is just
inserted into a DOM tree.
(WebCore::Node::removedFromAncestor): Ditto for removal.

* Source/WebCore/dom/Node.h:
(WebCore::Node::containsSelectionEndPoint const): Added.
(WebCore::Node::setContainsSelectionEndPoint): Added.

* Source/WebCore/editing/FrameSelection.cpp:
(WebCore::FrameSelection::setSelectionWithoutUpdatingAppearance):
(WebCore::setNodeContainsSelectionEndPoint): Added. Sets the node flag on all ancestor nodes given
a position.
(WebCore::FrameSelection::setNodeFlags): Added. Sets the node flag on ancestor nodes of each
selection end points: start, end, base, extent, focus, or anchor.
(WebCore::FrameSelection::nodeWillBeRemoved): Added the optimization.
(WebCore::FrameSelection::respondToNodeModification):
(WebCore::FrameSelection::willBeModified):

* Source/WebCore/editing/FrameSelection.h:

Canonical link: https://commits.webkit.org/276766@main



To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications


More information about the webkit-changes mailing list