Bug 1612828: part 3) Remove `nsresult` return type from `Selection::FindInsertionPoint`. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D61533

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mirko Brodesser 2020-02-05 12:22:08 +00:00
Родитель cc85009b5f
Коммит 09e3040bc2
2 изменённых файлов: 17 добавлений и 27 удалений

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

@ -713,12 +713,10 @@ static int32_t CompareToRangeEnd(const nsINode& aCompareNode,
aRange.EndOffset());
}
nsresult Selection::FindInsertionPoint(
int32_t Selection::FindInsertionPoint(
const nsTArray<StyledRange>* aElementArray, const nsINode& aPointNode,
int32_t aPointOffset,
int32_t (*aComparator)(const nsINode&, int32_t, const nsRange&),
int32_t* aInsertionPoint) {
*aInsertionPoint = 0;
int32_t (*aComparator)(const nsINode&, int32_t, const nsRange&)) {
int32_t beginSearch = 0;
int32_t endSearch = aElementArray->Length(); // one beyond what to check
@ -741,8 +739,7 @@ nsresult Selection::FindInsertionPoint(
} while (endSearch - beginSearch > 0);
}
*aInsertionPoint = beginSearch;
return NS_OK;
return beginSearch;
}
// Selection::SubtractRange
@ -1013,12 +1010,10 @@ nsresult Selection::MaybeAddRangeAndTruncateOverlaps(nsRange* aRange,
}
// Insert the new element into our "leftovers" array
int32_t insertionPoint;
// `aRange` is positioned, it has to have a start container.
rv = FindInsertionPoint(&temp, *aRange->GetStartContainer(),
aRange->StartOffset(), CompareToRangeStart,
&insertionPoint);
NS_ENSURE_SUCCESS(rv, rv);
// `aRange` is positioned, so it has to have a start container.
int32_t insertionPoint{FindInsertionPoint(&temp, *aRange->GetStartContainer(),
aRange->StartOffset(),
CompareToRangeStart)};
if (!temp.InsertElementAt(insertionPoint, StyledRange(aRange))) {
return NS_ERROR_OUT_OF_MEMORY;
@ -1168,11 +1163,8 @@ nsresult Selection::GetIndicesForInterval(
// Ranges that end before the given interval and begin after the given
// interval can be discarded
int32_t endsBeforeIndex;
if (NS_FAILED(FindInsertionPoint(&mRanges, *aEndNode, aEndOffset,
&CompareToRangeStart, &endsBeforeIndex))) {
return NS_OK;
}
int32_t endsBeforeIndex{FindInsertionPoint(&mRanges, *aEndNode, aEndOffset,
&CompareToRangeStart)};
if (endsBeforeIndex == 0) {
const nsRange* endRange = mRanges[endsBeforeIndex].mRange;
@ -1193,11 +1185,9 @@ nsresult Selection::GetIndicesForInterval(
}
aEndIndex = endsBeforeIndex;
int32_t beginsAfterIndex;
if (NS_FAILED(FindInsertionPoint(&mRanges, *aBeginNode, aBeginOffset,
&CompareToRangeEnd, &beginsAfterIndex))) {
return NS_OK;
}
int32_t beginsAfterIndex{FindInsertionPoint(
&mRanges, *aBeginNode, aBeginOffset, &CompareToRangeEnd)};
if (beginsAfterIndex == (int32_t)mRanges.Length())
return NS_OK; // optimization: all ranges are strictly before us

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

@ -734,18 +734,18 @@ class Selection final : public nsSupportsWeakReference,
/**
* Binary searches the given sorted array of ranges for the insertion point
* for the given node/offset. The given comparator is used, and the index
* where the point should appear in the array is placed in *aInsertionPoint.
* where the point should appear in the array is returned.
* If there is an item in the array equal to the input point (aPointNode,
* aPointOffset), we will return the index of this item.
*
* @param aInsertionPoint can be in [0, `aElementArray->Length()`].
* @return the index where the point should appear in the array. In
* [0, `aElementArray->Length()`].
*/
static nsresult FindInsertionPoint(
static int32_t FindInsertionPoint(
const nsTArray<StyledRange>* aElementArray, const nsINode& aPointNode,
int32_t aPointOffset,
int32_t (*aComparator)(const nsINode&, int32_t, const nsRange&),
int32_t* aInsertionPoint);
int32_t (*aComparator)(const nsINode&, int32_t, const nsRange&));
bool HasEqualRangeBoundariesAt(const nsRange& aRange,
int32_t aRangeIndex) const;