From 09e3040bc24f745df86d9b6cd8e11255ee6db023 Mon Sep 17 00:00:00 2001 From: Mirko Brodesser Date: Wed, 5 Feb 2020 12:22:08 +0000 Subject: [PATCH] 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 --- dom/base/Selection.cpp | 34 ++++++++++++---------------------- dom/base/Selection.h | 10 +++++----- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/dom/base/Selection.cpp b/dom/base/Selection.cpp index 85983d899504..2bbc3ab60a21 100644 --- a/dom/base/Selection.cpp +++ b/dom/base/Selection.cpp @@ -713,12 +713,10 @@ static int32_t CompareToRangeEnd(const nsINode& aCompareNode, aRange.EndOffset()); } -nsresult Selection::FindInsertionPoint( +int32_t Selection::FindInsertionPoint( const nsTArray* 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 diff --git a/dom/base/Selection.h b/dom/base/Selection.h index 10f269a83fc8..e4db62acfc2b 100644 --- a/dom/base/Selection.h +++ b/dom/base/Selection.h @@ -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* 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;