Bug 1628715 - Part 9: Add MOZ_NONNULL_RETURN to InsertElementSorted. r=xpcom-reviewers,nika

Differential Revision: https://phabricator.services.mozilla.com/D70833
This commit is contained in:
Simon Giesecke 2020-04-24 13:31:38 +00:00
parent 736ddc6d90
commit 6d5ba85520
2 changed files with 27 additions and 22 deletions

View File

@ -81,11 +81,9 @@ void TextTrackList::AddTextTrack(TextTrack* aTextTrack,
if (mTextTracks.Contains(aTextTrack)) {
return;
}
if (mTextTracks.InsertElementSorted(aTextTrack, aCompareTT)) {
aTextTrack->SetTextTrackList(this);
CreateAndDispatchTrackEventRunner(aTextTrack,
NS_LITERAL_STRING("addtrack"));
}
mTextTracks.InsertElementSorted(aTextTrack, aCompareTT);
aTextTrack->SetTextTrackList(this);
CreateAndDispatchTrackEventRunner(aTextTrack, NS_LITERAL_STRING("addtrack"));
}
TextTrack* TextTrackList::GetTrackById(const nsAString& aId) {

View File

@ -1712,40 +1712,34 @@ class nsTArray_Impl
return IndexOfFirstElementGt(aItem, nsDefaultComparator<elem_type, Item>());
}
// Inserts |aItem| at such an index to guarantee that if the array
// was previously sorted, it will remain sorted after this
// insertion.
protected:
template <class Item, class Comparator, typename ActualAlloc = Alloc>
elem_type* InsertElementSorted(Item&& aItem, const Comparator& aComp) {
private:
template <typename ActualAlloc, class Item, class Comparator>
elem_type* InsertElementSortedInternal(Item&& aItem,
const Comparator& aComp) {
index_type index = IndexOfFirstElementGt<Item, Comparator>(aItem, aComp);
return InsertElementAtInternal<ActualAlloc>(index,
std::forward<Item>(aItem));
}
// Inserts |aItem| at such an index to guarantee that if the array
// was previously sorted, it will remain sorted after this
// insertion.
public:
template <class Item, class Comparator>
[[nodiscard]] elem_type* InsertElementSorted(Item&& aItem,
const Comparator& aComp,
const mozilla::fallible_t&) {
return InsertElementSorted<Item, Comparator, FallibleAlloc>(
std::forward<Item>(aItem), aComp);
return InsertElementSortedInternal<FallibleAlloc>(std::forward<Item>(aItem),
aComp);
}
// A variation on the InsertElementSorted method defined above.
protected:
template <class Item, typename ActualAlloc = Alloc>
elem_type* InsertElementSorted(Item&& aItem) {
nsDefaultComparator<elem_type, Item> comp;
return InsertElementSorted<Item, decltype(comp), ActualAlloc>(
std::forward<Item>(aItem), comp);
}
public:
template <class Item>
[[nodiscard]] elem_type* InsertElementSorted(Item&& aItem,
const mozilla::fallible_t&) {
return InsertElementSorted<Item, FallibleAlloc>(std::forward<Item>(aItem));
return InsertElementSortedInternal<FallibleAlloc>(
std::forward<Item>(aItem), nsDefaultComparator<elem_type, Item>{});
}
private:
@ -2820,6 +2814,19 @@ class nsTArray : public nsTArray_Impl<E, nsTArrayInfallibleAllocator> {
return ReplaceElementsAt(aStart, aCount, &aItem, 1);
}
template <class Item, class Comparator>
MOZ_NONNULL_RETURN elem_type* InsertElementSorted(Item&& aItem,
const Comparator& aComp) {
return this->template InsertElementSortedInternal<InfallibleAlloc>(
std::forward<Item>(aItem), aComp);
}
template <class Item>
MOZ_NONNULL_RETURN elem_type* InsertElementSorted(Item&& aItem) {
return this->template InsertElementSortedInternal<InfallibleAlloc>(
std::forward<Item>(aItem), nsDefaultComparator<elem_type, Item>{});
}
template <class... Args>
MOZ_NONNULL_RETURN typename base_type::elem_type* EmplaceBack(
Args&&... aArgs) {