From 850cbc20a8de04fea51c8821b765d5296f2955ac Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Mon, 27 Apr 2020 10:08:46 +0000 Subject: [PATCH] Bug 1631391 - Simplify implementation of ReplaceElementAt. r=xpcom-reviewers,nika Depends on D71721 Differential Revision: https://phabricator.services.mozilla.com/D71723 --- xpcom/ds/nsTArray.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/xpcom/ds/nsTArray.h b/xpcom/ds/nsTArray.h index a0b3f8b72cd8..793c8bba91de 100644 --- a/xpcom/ds/nsTArray.h +++ b/xpcom/ds/nsTArray.h @@ -1623,12 +1623,11 @@ class nsTArray_Impl // A variation on the ReplaceElementsAt method defined above. template mozilla::NotNull 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(aIndex, 1, &aItem, 1)); + Item&& aItem) { + elem_type* const elem = &ElementAt(aIndex); + elem_traits::Destruct(elem); + elem_traits::Construct(elem, std::forward(aItem)); + return mozilla::WrapNotNullUnchecked(elem); } // InsertElementsAt is ReplaceElementsAt with 0 elements to replace.