Commit 599db6f7 authored by Oriol Brufau's avatar Oriol Brufau Committed by Chromium LUCI CQ

[editing] Optimize MostBackwardOrForwardCaretPosition

MostBackwardOrForwardCaretPosition was added in r832706, and this caused
a -1.8% perf regression for line-layout-repeat-append-select.html

The reason is that the function adjusts the obtained candidate position
to avoid crossing shadow boundaries.

This patch adds fast paths for the common cases when both the candidate
and the original position are neither in a shadow tree nor are shadow
hosts themselves.

Bug: 1154646
Change-Id: I036e9044e2b8c921b466595be9661efbc852aa1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2569740
Commit-Queue: Oriol Brufau <obrufau@igalia.com>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833152}
parent 4d4f8eb3
......@@ -620,16 +620,24 @@ static Position MostBackwardOrForwardCaretPosition(
const Position& position,
EditingBoundaryCrossingRule rule,
F AlgorithmInFlatTree) {
if (position.IsNull())
Node* position_anchor = position.AnchorNode();
if (!position_anchor)
return Position();
DCHECK(position.IsValidFor(*position.GetDocument()));
// Find the most backward or forward caret position in the flat tree.
const Position& candidate = ToPositionInDOMTree(
AlgorithmInFlatTree(ToPositionInFlatTree(position), rule));
if (candidate.IsNull())
Node* candidate_anchor = candidate.AnchorNode();
if (!candidate_anchor)
return candidate;
// Fast path for common cases when there is no shadow involved.
if (!position_anchor->IsInShadowTree() && !IsShadowHost(position_anchor) &&
!candidate_anchor->IsInShadowTree() && !IsShadowHost(candidate_anchor)) {
return candidate;
}
// Adjust the candidate to avoid crossing shadow boundaries.
const SelectionInDOMTree& selection =
SelectionInDOMTree::Builder()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment