Bug 1745862 - part 3: Make `RangeBoundaryBase::DetermineOffsetFromReference` check `mRef->IsBeingRemoved` before computing its index r=mbrodesser

`nsINode::ComputeIndexOf` may be expensive especially when the node is not
in the parent node.  Therefore, `DetermineOffsetFromReference` should check
whether `mRef` has already been removed from the child node chain of `mParent`.
Then, it explains the reason why `ComputeIndexOf` may return `Nothing` clearer.

Depends on D135190

Differential Revision: https://phabricator.services.mozilla.com/D135823
This commit is contained in:
Masayuki Nakano 2022-01-13 13:25:16 +00:00
Родитель e4e35dbacd
Коммит 396dde1072
1 изменённых файлов: 6 добавлений и 6 удалений

Просмотреть файл

@ -206,15 +206,15 @@ class RangeBoundaryBase {
MOZ_ASSERT(mRef->GetParentNode() == mParent);
MOZ_ASSERT(mOffset.isNothing());
const Maybe<uint32_t> index = mParent->ComputeIndexOf(mRef);
// If mRef is **being** removed from mParent, ComputeIndexOf returns
// Nothing because mRef has already been removed from the child node chain
// of mParent.
if (index.isNothing()) {
if (mRef->IsBeingRemoved()) {
// ComputeIndexOf would return nothing because mRef has already been
// removed from the child node chain of mParent.
return;
}
const Maybe<uint32_t> index = mParent->ComputeIndexOf(mRef);
MOZ_ASSERT(*index != UINT32_MAX);
mOffset.emplace(*index + 1u);
mOffset.emplace(MOZ_LIKELY(index.isSome()) ? *index + 1u : 0u);
}
void InvalidateOffset() {