Bug 1631391 - Simplify implementation of ReplaceElementAt. r=xpcom-reviewers,nika

Depends on D71721

Differential Revision: https://phabricator.services.mozilla.com/D71723
This commit is contained in:
Simon Giesecke 2020-04-27 10:08:46 +00:00
Родитель 07d72f57f6
Коммит 850cbc20a8
1 изменённых файлов: 5 добавлений и 6 удалений

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

@ -1623,12 +1623,11 @@ class nsTArray_Impl
// A variation on the ReplaceElementsAt method defined above.
template <class Item>
mozilla::NotNull<elem_type*> ReplaceElementAt(index_type aIndex,
const Item& aItem) {
// This can never fail as the oldCount and newCount are the same.
// XXX(Bug 1631391) Still, we might better use a different implementation,
// which better exploits that the old and new count are the same.
return mozilla::WrapNotNullUnchecked(
ReplaceElementsAtInternal<InfallibleAlloc>(aIndex, 1, &aItem, 1));
Item&& aItem) {
elem_type* const elem = &ElementAt(aIndex);
elem_traits::Destruct(elem);
elem_traits::Construct(elem, std::forward<Item>(aItem));
return mozilla::WrapNotNullUnchecked(elem);
}
// InsertElementsAt is ReplaceElementsAt with 0 elements to replace.