Bug 1628715 - Part 15: Replace MOZ_NONNULL_RETURN by returning NotNull<elem_type*>. r=xpcom-reviewers,necko-reviewers,dragana,nika

Differential Revision: https://phabricator.services.mozilla.com/D71300
This commit is contained in:
Simon Giesecke 2020-04-24 13:35:27 +00:00
Родитель 9a017967d6
Коммит 2d8c4390b7
21 изменённых файлов: 179 добавлений и 162 удалений

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

@ -673,7 +673,7 @@ bool BrowsingContext::HasOpener() const {
}
void BrowsingContext::GetChildren(Children& aChildren) {
MOZ_ALWAYS_TRUE(aChildren.AppendElements(mChildren));
aChildren.AppendElements(mChildren);
}
void BrowsingContext::GetWindowContexts(

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

@ -12062,9 +12062,7 @@ nsresult Document::ScheduleFrameRequestCallback(FrameRequestCallback& aCallback,
}
int32_t newHandle = ++mFrameRequestCallbackCounter;
DebugOnly<FrameRequest*> request =
mFrameRequestCallbacks.AppendElement(FrameRequest(aCallback, newHandle));
NS_ASSERTION(request, "This is supposed to be infallible!");
mFrameRequestCallbacks.AppendElement(FrameRequest(aCallback, newHandle));
UpdateFrameRequestCallbackSchedulingState();
*aHandle = newHandle;

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

@ -10025,14 +10025,14 @@ struct CommonPopulateResponseHelper {
}
template <typename Response>
void FillKeys(Response* const aResponse) {
void FillKeys(Response& aResponse) {
MOZ_ASSERT(!mPosition.IsUnset());
aResponse->key() = std::move(mPosition);
aResponse.key() = std::move(mPosition);
}
template <typename Response>
static size_t GetKeySize(const Response* const aResponse) {
return aResponse->key().GetBuffer().Length();
static size_t GetKeySize(const Response& aResponse) {
return aResponse.key().GetBuffer().Length();
}
protected:
@ -10075,20 +10075,20 @@ struct IndexPopulateResponseHelper : CommonPopulateResponseHelper {
}
template <typename Response>
void FillKeys(Response* const aResponse) {
void FillKeys(Response& aResponse) {
MOZ_ASSERT(!mLocaleAwarePosition.IsUnset());
MOZ_ASSERT(!mObjectStorePosition.IsUnset());
CommonPopulateResponseHelper::FillKeys(aResponse);
aResponse->sortKey() = std::move(mLocaleAwarePosition);
aResponse->objectKey() = std::move(mObjectStorePosition);
aResponse.sortKey() = std::move(mLocaleAwarePosition);
aResponse.objectKey() = std::move(mObjectStorePosition);
}
template <typename Response>
static size_t GetKeySize(const Response* const aResponse) {
static size_t GetKeySize(Response& aResponse) {
return CommonPopulateResponseHelper::GetKeySize(aResponse) +
aResponse->sortKey().GetBuffer().Length() +
aResponse->objectKey().GetBuffer().Length();
aResponse.sortKey().GetBuffer().Length() +
aResponse.objectKey().GetBuffer().Length();
}
private:
@ -10102,12 +10102,11 @@ struct KeyPopulateResponseHelper {
}
template <typename Response>
static constexpr void MaybeFillCloneInfo(Response* const /*aResponse*/,
static constexpr void MaybeFillCloneInfo(Response& /*aResponse*/,
FilesArray* const /*aFiles*/) {}
template <typename Response>
static constexpr size_t MaybeGetCloneInfoSize(
const Response* const /*aResponse*/) {
static constexpr size_t MaybeGetCloneInfoSize(const Response& /*aResponse*/) {
return 0;
}
};
@ -10138,15 +10137,15 @@ struct ValuePopulateResponseHelper {
}
template <typename Response>
void MaybeFillCloneInfo(Response* const aResponse, FilesArray* const aFiles) {
void MaybeFillCloneInfo(Response& aResponse, FilesArray* const aFiles) {
auto cloneInfo = mCloneInfo.release();
aResponse->cloneInfo().data().data = cloneInfo.ReleaseData();
aResponse.cloneInfo().data().data = cloneInfo.ReleaseData();
aFiles->AppendElement(cloneInfo.ReleaseFiles());
}
template <typename Response>
static size_t MaybeGetCloneInfoSize(const Response* const aResponse) {
return aResponse->cloneInfo().data().data.Size();
static size_t MaybeGetCloneInfoSize(const Response& aResponse) {
return aResponse.cloneInfo().data().data.Size();
}
private:
@ -26744,7 +26743,7 @@ CursorOpBaseHelperBase<CursorType>::PopulateResponseFromStatement(
}
auto& responses = populateResponseHelper.GetTypedResponse(&mOp.mResponse);
auto* response = responses.AppendElement();
auto& response = *responses.AppendElement();
populateResponseHelper.FillKeys(response);
if constexpr (!CursorTypeTraits<CursorType>::IsKeyOnlyCursor) {

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

@ -52,7 +52,7 @@ JSWindowActorProtocol::FromIPC(const JSWindowActorInfo& aInfo) {
proto->mChild.mEvents.SetCapacity(aInfo.events().Length());
for (auto& ipc : aInfo.events()) {
auto* event = proto->mChild.mEvents.AppendElement();
auto event = proto->mChild.mEvents.AppendElement();
event->mName.Assign(ipc.name());
event->mFlags.mCapture = ipc.capture();
event->mFlags.mInSystemGroup = ipc.systemGroup();
@ -79,7 +79,7 @@ JSWindowActorInfo JSWindowActorProtocol::ToIPC() {
info.events().SetCapacity(mChild.mEvents.Length());
for (auto& event : mChild.mEvents) {
auto* ipc = info.events().AppendElement();
auto ipc = info.events().AppendElement();
ipc->name().Assign(event.mName);
ipc->capture() = event.mFlags.mCapture;
ipc->systemGroup() = event.mFlags.mInSystemGroup;
@ -312,7 +312,7 @@ extensions::MatchPatternSet* JSWindowActorProtocol::GetURIMatcher() {
nsTArray<OwningStringOrMatchPattern> patterns;
patterns.SetCapacity(mMatches.Length());
for (nsString& s : mMatches) {
auto* entry = patterns.AppendElement();
auto entry = patterns.AppendElement();
entry->SetAsString() = s;
}

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

@ -381,9 +381,7 @@ int32_t XRSession::RequestAnimationFrame(XRFrameRequestCallback& aCallback,
int32_t handle = ++mFrameRequestCallbackCounter;
DebugOnly<XRFrameRequest*> request =
mFrameRequestCallbacks.AppendElement(XRFrameRequest(aCallback, handle));
NS_ASSERTION(request, "This is supposed to be infallible!");
mFrameRequestCallbacks.AppendElement(XRFrameRequest(aCallback, handle));
return handle;
}

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

@ -389,9 +389,7 @@ nsresult VRManagerChild::ScheduleFrameRequestCallback(
}
int32_t newHandle = ++mFrameRequestCallbackCounter;
DebugOnly<XRFrameRequest*> request = mFrameRequestCallbacks.AppendElement(
XRFrameRequest(aCallback, newHandle));
NS_ASSERTION(request, "This is supposed to be infallible!");
mFrameRequestCallbacks.AppendElement(XRFrameRequest(aCallback, newHandle));
*aHandle = newHandle;
return NS_OK;

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

@ -2659,7 +2659,7 @@ struct MOZ_STACK_CLASS nsGridContainerFrame::GridReflowInput {
uint32_t offsetInOppositeAxis = aRangeInOppositeAxis.mStart;
uint32_t gridEndInOppositeAxis = aRangeInOppositeAxis.Extent();
for (const auto& subgridItem : aItems) {
auto* newItem = aResult.AppendElement(
auto newItem = aResult.AppendElement(
isOrthogonal ? subgridItem.Transpose() : subgridItem);
if (MOZ_UNLIKELY(!isSameDirInAxis)) {
newItem->ReverseDirection(aAxis, gridEndInAxis);

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

@ -783,9 +783,7 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
aIsPrintPreview);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(
printData->mPrintDocList.AppendElement(printData->mPrintObject.get()),
NS_ERROR_OUT_OF_MEMORY);
printData->mPrintDocList.AppendElement(printData->mPrintObject.get());
printData->mIsParentAFrameSet = IsParentAFrameSet(docShell);
printData->mPrintObject->mFrameType =

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

@ -1174,7 +1174,10 @@ bool nsCellMap::Grow(nsTableCellMap& aMap, int32_t aNumRows,
uint32_t startRowIndex = (aRowIndex >= 0) ? aRowIndex : mRows.Length();
NS_ASSERTION(startRowIndex <= mRows.Length(), "Missing grow call inbetween");
return mRows.InsertElementsAt(startRowIndex, aNumRows, numCols) != nullptr;
// XXX Change the return type of this function to void, or use a fallible
// operation.
mRows.InsertElementsAt(startRowIndex, aNumRows, numCols);
return true;
}
void nsCellMap::GrowRow(CellDataArray& aRow, int32_t aNumCols)
@ -1642,16 +1645,8 @@ void nsCellMap::ExpandWithCells(nsTableCellMap& aMap,
if (insertionIndex > startColIndex) {
insertionIndex = startColIndex;
}
if (!row.InsertElementsAt(insertionIndex,
endColIndex - insertionIndex + 1,
(CellData*)nullptr) &&
rowX == aRowIndex) {
// Failed to insert the slots, and this is the very first row. That
// means that we need to clean up |origData| before returning, since
// the cellmap doesn't own it yet.
DestroyCellData(origData);
return;
}
row.InsertElementsAt(insertionIndex, endColIndex - insertionIndex + 1,
(CellData*)nullptr);
for (int32_t colX = startColIndex; colX <= endColIndex; colX++) {
CellData* data = origData;

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

@ -25,6 +25,9 @@
namespace mozilla {
template <typename T>
class NotNull;
/** Set the contents of |aT| to 0. */
template <typename T>
static MOZ_ALWAYS_INLINE void PodZero(T* aT) {
@ -44,6 +47,12 @@ static MOZ_ALWAYS_INLINE void PodZero(T* aT, size_t aNElem) {
}
}
/** Set the contents of |aNElem| elements starting at |aT| to 0. */
template <typename T>
static MOZ_ALWAYS_INLINE void PodZero(NotNull<T*> aT, size_t aNElem) {
PodZero(aT.get(), aNElem);
}
/*
* Arrays implicitly convert to pointers to their first element, which is
* dangerous when combined with the above PodZero definitions. Adding an

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

@ -571,7 +571,7 @@ void nsFileInputStream::SerializeInternal(
FileHandleType fd = FileHandleType(PR_FileDesc2NativeHandle(mFD));
NS_ASSERTION(fd, "This should never be null!");
DebugOnly<FileDescriptor*> dbgFD = aFileDescriptors.AppendElement(fd);
DebugOnly dbgFD = aFileDescriptors.AppendElement(fd);
NS_ASSERTION(dbgFD->IsValid(), "Sending an invalid file descriptor!");
params.fileDescriptorIndex() = aFileDescriptors.Length() - 1;

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

@ -177,7 +177,7 @@ StorageBaseStatementInternal::ExecuteAsync(
StatementData data;
nsresult rv = getAsynchronousStatementData(data);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(stmts.AppendElement(data), NS_ERROR_OUT_OF_MEMORY);
stmts.AppendElement(data);
// Dispatch to the background
return AsyncExecuteStatements::execute(stmts, mDBConnection,

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

@ -317,8 +317,7 @@ BindingParams::BindByIndex(uint32_t aIndex, nsIVariant* aValue) {
(void)mParameters.SetLength(aIndex);
(void)mParameters.AppendElement(variant);
} else {
NS_ENSURE_TRUE(mParameters.ReplaceElementAt(aIndex, variant),
NS_ERROR_OUT_OF_MEMORY);
mParameters.ReplaceElementAt(aIndex, variant);
}
return NS_OK;
}
@ -335,8 +334,7 @@ AsyncBindingParams::BindByIndex(uint32_t aIndex, nsIVariant* aValue) {
mParameters.SetLength(aIndex);
mParameters.AppendElement(variant);
} else {
NS_ENSURE_TRUE(mParameters.ReplaceElementAt(aIndex, variant),
NS_ERROR_OUT_OF_MEMORY);
mParameters.ReplaceElementAt(aIndex, variant);
}
return NS_OK;
}

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

@ -57,7 +57,7 @@ BindingParamsArray::AddParams(mozIStorageBindingParams* aParameters) {
// Check to make sure that this set of parameters was created with us.
if (params->getOwner() != this) return NS_ERROR_UNEXPECTED;
NS_ENSURE_TRUE(mArray.AppendElement(params), NS_ERROR_OUT_OF_MEMORY);
mArray.AppendElement(params);
// Lock the parameters only after we've successfully added them.
params->lock();

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

@ -1866,7 +1866,7 @@ Connection::ExecuteAsync(
"Statement must be from this database connection!");
// Now append it to our array.
NS_ENSURE_TRUE(stmts.AppendElement(data), NS_ERROR_OUT_OF_MEMORY);
stmts.AppendElement(data);
}
// Dispatch to the background

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

@ -1855,8 +1855,7 @@ History::VisitURI(nsIWidget* aWidget, nsIURI* aURI, nsIURI* aLastVisitedURI,
}
nsTArray<VisitData> placeArray(1);
NS_ENSURE_TRUE(placeArray.AppendElement(VisitData(aURI, aLastVisitedURI)),
NS_ERROR_OUT_OF_MEMORY);
placeArray.AppendElement(VisitData(aURI, aLastVisitedURI));
VisitData& place = placeArray.ElementAt(0);
NS_ENSURE_FALSE(place.spec.IsEmpty(), NS_ERROR_INVALID_ARG);

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

@ -1763,7 +1763,7 @@ nsresult nsNavBookmarks::GetBookmarksForURI(
rv = stmt->GetInt32(6, &bookmark.syncStatus);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(aBookmarks.AppendElement(bookmark), NS_ERROR_OUT_OF_MEMORY);
aBookmarks.AppendElement(bookmark);
}
return NS_OK;

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

@ -428,7 +428,7 @@ nsresult nsNavHistory::TokensToQuery(const nsTArray<QueryKeyValuePair>& aTokens,
// parent folders (guids)
} else if (kvp.key.EqualsLiteral(QUERYKEY_PARENT)) {
NS_ENSURE_TRUE(parents.AppendElement(kvp.value), NS_ERROR_OUT_OF_MEMORY);
parents.AppendElement(kvp.value);
// uri
} else if (kvp.key.EqualsLiteral(QUERYKEY_URI)) {
@ -462,7 +462,7 @@ nsresult nsNavHistory::TokensToQuery(const nsTArray<QueryKeyValuePair>& aTokens,
NS_UnescapeURL(unescaped); // modifies input
NS_ConvertUTF8toUTF16 tag(unescaped);
if (!tags.Contains(tag)) {
NS_ENSURE_TRUE(tags.AppendElement(tag), NS_ERROR_OUT_OF_MEMORY);
tags.AppendElement(tag);
}
// not tags
@ -474,8 +474,7 @@ nsresult nsNavHistory::TokensToQuery(const nsTArray<QueryKeyValuePair>& aTokens,
uint32_t transition = kvp.value.ToInteger(&rv);
if (NS_SUCCEEDED(rv)) {
if (!transitions.Contains(transition))
NS_ENSURE_TRUE(transitions.AppendElement(transition),
NS_ERROR_OUT_OF_MEMORY);
transitions.AppendElement(transition);
} else {
NS_WARNING("Invalid Int32 transition value.");
}

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

@ -333,7 +333,7 @@ LoginReputationService::QueryReputation(
// mQueryRequests is an array used to maintain the ownership of
// |QueryRequest|. We ensure that |QueryRequest| is always valid until
// Finish() is called or LoginReputationService is shutdown.
auto* request =
auto request =
mQueryRequests.AppendElement(MakeUnique<QueryRequest>(aQuery, aCallback));
return QueryLoginWhitelist(request->get());

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

@ -26,6 +26,7 @@
#include "mozilla/FunctionTypeTraits.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/NotNull.h"
#include "mozilla/ReverseIterator.h"
#include "mozilla/Span.h"
#include "mozilla/TypeTraits.h"
@ -217,6 +218,10 @@ struct nsTArrayInfallibleAllocatorBase {
MOZ_CRASH("infallible nsTArray should never convert false to ResultType");
}
}
template <typename T>
static constexpr ResultType ConvertBoolToResultType(
const mozilla::NotNull<T>& aValue) {}
};
struct nsTArrayFallibleAllocator : nsTArrayFallibleAllocatorBase {
@ -1617,10 +1622,13 @@ class nsTArray_Impl
// A variation on the ReplaceElementsAt method defined above.
template <class Item>
MOZ_NONNULL_RETURN elem_type* ReplaceElementAt(index_type aIndex,
const Item& aItem) {
mozilla::NotNull<elem_type*> ReplaceElementAt(index_type aIndex,
const Item& aItem) {
// This can never fail as the oldCount and newCount are the same.
return ReplaceElementsAtInternal<InfallibleAlloc>(aIndex, 1, &aItem, 1);
// 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));
}
// InsertElementsAt is ReplaceElementsAt with 0 elements to replace.
@ -1686,11 +1694,11 @@ class nsTArray_Impl
//
// would accomplish the same thing as long as T has the appropriate moving
// operator=, but some types don't for various reasons.
elem_type* ReconstructElementAt(index_type aIndex) MOZ_NONNULL_RETURN {
mozilla::NotNull<elem_type*> ReconstructElementAt(index_type aIndex) {
elem_type* elem = &ElementAt(aIndex);
elem_traits::Destruct(elem);
elem_traits::Construct(elem);
return elem;
return mozilla::WrapNotNullUnchecked(elem);
}
// This method searches for the smallest index of an element that is strictly
@ -2712,141 +2720,159 @@ class nsTArray : public nsTArray_Impl<E, nsTArrayInfallibleAllocator> {
using base_type::SetLength;
template <class Item>
MOZ_NONNULL_RETURN elem_type* AppendElements(const Item* aArray,
size_type aArrayLen) {
return this->template AppendElementsInternal<InfallibleAlloc>(aArray,
aArrayLen);
mozilla::NotNull<elem_type*> AppendElements(const Item* aArray,
size_type aArrayLen) {
return mozilla::WrapNotNullUnchecked(
this->template AppendElementsInternal<InfallibleAlloc>(aArray,
aArrayLen));
}
template <class Item>
MOZ_NONNULL_RETURN elem_type* AppendElements(mozilla::Span<Item> aSpan) {
return this->template AppendElementsInternal<InfallibleAlloc>(
aSpan.Elements(), aSpan.Length());
mozilla::NotNull<elem_type*> AppendElements(mozilla::Span<Item> aSpan) {
return mozilla::WrapNotNullUnchecked(
this->template AppendElementsInternal<InfallibleAlloc>(aSpan.Elements(),
aSpan.Length()));
}
template <class Item, class Allocator>
MOZ_NONNULL_RETURN elem_type* AppendElements(
mozilla::NotNull<elem_type*> AppendElements(
const nsTArray_Impl<Item, Allocator>& aArray) {
return this->template AppendElementsInternal<InfallibleAlloc>(
aArray.Elements(), aArray.Length());
return mozilla::WrapNotNullUnchecked(
this->template AppendElementsInternal<InfallibleAlloc>(
aArray.Elements(), aArray.Length()));
}
template <class Item, class Allocator>
MOZ_NONNULL_RETURN elem_type* AppendElements(
mozilla::NotNull<elem_type*> AppendElements(
nsTArray_Impl<Item, Allocator>&& aArray) {
return this->template AppendElementsInternal<InfallibleAlloc>(
std::move(aArray));
return mozilla::WrapNotNullUnchecked(
this->template AppendElementsInternal<InfallibleAlloc>(
std::move(aArray)));
}
template <class Item>
MOZ_NONNULL_RETURN elem_type* AppendElement(Item&& aItem) {
return this->template AppendElementInternal<InfallibleAlloc>(
std::forward<Item>(aItem));
mozilla::NotNull<elem_type*> AppendElement(Item&& aItem) {
return mozilla::WrapNotNullUnchecked(
this->template AppendElementInternal<InfallibleAlloc>(
std::forward<Item>(aItem)));
}
MOZ_NONNULL_RETURN elem_type* AppendElements(size_type aCount) {
return this->template AppendElementsInternal<InfallibleAlloc>(aCount);
mozilla::NotNull<elem_type*> AppendElements(size_type aCount) {
return mozilla::WrapNotNullUnchecked(
this->template AppendElementsInternal<InfallibleAlloc>(aCount));
}
MOZ_NONNULL_RETURN elem_type* AppendElement() {
return this->template AppendElementsInternal<InfallibleAlloc>(1);
mozilla::NotNull<elem_type*> AppendElement() {
return mozilla::WrapNotNullUnchecked(
this->template AppendElementsInternal<InfallibleAlloc>(1));
}
mozilla::NotNull<elem_type*> InsertElementsAt(index_type aIndex,
size_type aCount) {
return mozilla::WrapNotNullUnchecked(
this->template InsertElementsAtInternal<InfallibleAlloc>(aIndex,
aCount));
}
template <class Item>
MOZ_NONNULL_RETURN elem_type* InsertElementsAt(index_type aIndex,
mozilla::NotNull<elem_type*> InsertElementsAt(index_type aIndex,
size_type aCount,
const Item& aItem) {
return mozilla::WrapNotNullUnchecked(
this->template InsertElementsAtInternal<InfallibleAlloc>(aIndex, aCount,
aItem));
}
template <class Item>
mozilla::NotNull<elem_type*> InsertElementsAt(index_type aIndex,
const Item* aArray,
size_type aArrayLen) {
return mozilla::WrapNotNullUnchecked(
this->template ReplaceElementsAtInternal<InfallibleAlloc>(
aIndex, 0, aArray, aArrayLen));
}
template <class Item, class Allocator>
mozilla::NotNull<elem_type*> InsertElementsAt(
index_type aIndex, const nsTArray_Impl<Item, Allocator>& aArray) {
return mozilla::WrapNotNullUnchecked(
this->template ReplaceElementsAtInternal<InfallibleAlloc>(
aIndex, 0, aArray.Elements(), aArray.Length()));
}
template <class Item>
mozilla::NotNull<elem_type*> InsertElementsAt(index_type aIndex,
mozilla::Span<Item> aSpan) {
return mozilla::WrapNotNullUnchecked(
this->template ReplaceElementsAtInternal<InfallibleAlloc>(
aIndex, 0, aSpan.Elements(), aSpan.Length()));
}
mozilla::NotNull<elem_type*> InsertElementAt(index_type aIndex) {
return mozilla::WrapNotNullUnchecked(
this->template InsertElementAtInternal<InfallibleAlloc>(aIndex));
}
template <class Item>
mozilla::NotNull<elem_type*> InsertElementAt(index_type aIndex,
Item&& aItem) {
return mozilla::WrapNotNullUnchecked(
this->template InsertElementAtInternal<InfallibleAlloc>(
aIndex, std::forward<Item>(aItem)));
}
template <class Item>
mozilla::NotNull<elem_type*> ReplaceElementsAt(index_type aStart,
size_type aCount,
const Item* aArray,
size_type aArrayLen) {
return this->template ReplaceElementsAtInternal<InfallibleAlloc>(
aIndex, 0, aArray, aArrayLen);
}
template <class Item, class Allocator>
MOZ_NONNULL_RETURN elem_type* InsertElementsAt(
index_type aIndex, const nsTArray_Impl<Item, Allocator>& aArray) {
return this->template ReplaceElementsAtInternal<InfallibleAlloc>(
aIndex, 0, aArray.Elements(), aArray.Length());
}
elem_type* InsertElementsAt(index_type aIndex,
size_type aCount) MOZ_NONNULL_RETURN {
return this->template InsertElementsAtInternal<InfallibleAlloc>(aIndex,
aCount);
return mozilla::WrapNotNullUnchecked(
this->template ReplaceElementsAtInternal<InfallibleAlloc>(
aStart, aCount, aArray, aArrayLen));
}
template <class Item>
MOZ_NONNULL_RETURN elem_type* InsertElementsAt(index_type aIndex,
mozilla::NotNull<elem_type*> ReplaceElementsAt(index_type aStart,
size_type aCount,
const Item& aItem) {
return this->template InsertElementsAtInternal<InfallibleAlloc>(
aIndex, aCount, aItem);
}
template <class Item>
MOZ_NONNULL_RETURN elem_type* InsertElementsAt(index_type aIndex,
mozilla::Span<Item> aSpan) {
return this->template ReplaceElementsAtInternal<InfallibleAlloc>(
aIndex, 0, aSpan.Elements(), aSpan.Length());
}
MOZ_NONNULL_RETURN elem_type* InsertElementAt(index_type aIndex) {
return this->template InsertElementAtInternal<InfallibleAlloc>(aIndex);
}
template <class Item>
MOZ_NONNULL_RETURN elem_type* InsertElementAt(index_type aIndex,
Item&& aItem) {
return this->template InsertElementAtInternal<InfallibleAlloc>(
aIndex, std::forward<Item>(aItem));
}
template <class Item>
MOZ_NONNULL_RETURN elem_type* ReplaceElementsAt(index_type aStart,
size_type aCount,
const Item* aArray,
size_type aArrayLen) {
return this->template ReplaceElementsAtInternal<InfallibleAlloc>(
aStart, aCount, aArray, aArrayLen);
}
template <class Item>
MOZ_NONNULL_RETURN elem_type* ReplaceElementsAt(
index_type aStart, size_type aCount, const nsTArray<Item>& aArray) {
const nsTArray<Item>& aArray) {
return ReplaceElementsAt(aStart, aCount, aArray.Elements(),
aArray.Length());
}
template <class Item>
MOZ_NONNULL_RETURN elem_type* ReplaceElementsAt(index_type aStart,
size_type aCount,
mozilla::Span<Item> aSpan) {
mozilla::NotNull<elem_type*> ReplaceElementsAt(index_type aStart,
size_type aCount,
mozilla::Span<Item> aSpan) {
return ReplaceElementsAt(aStart, aCount, aSpan.Elements(), aSpan.Length());
}
template <class Item>
MOZ_NONNULL_RETURN elem_type* ReplaceElementsAt(index_type aStart,
size_type aCount,
const Item& aItem) {
mozilla::NotNull<elem_type*> ReplaceElementsAt(index_type aStart,
size_type aCount,
const Item& aItem) {
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);
mozilla::NotNull<elem_type*> InsertElementSorted(Item&& aItem,
const Comparator& aComp) {
return mozilla::WrapNotNullUnchecked(
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>{});
mozilla::NotNull<elem_type*> InsertElementSorted(Item&& aItem) {
return mozilla::WrapNotNullUnchecked(
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) {
return this->template EmplaceBackInternal<InfallibleAlloc, Args...>(
std::forward<Args>(aArgs)...);
mozilla::NotNull<elem_type*> EmplaceBack(Args&&... aArgs) {
return mozilla::WrapNotNullUnchecked(
this->template EmplaceBackInternal<InfallibleAlloc, Args...>(
std::forward<Args>(aArgs)...));
}
};

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

@ -256,7 +256,7 @@ TEST(TArray, test_object_array)
size_t i;
for (i = 0; i < ArrayLength(kdata); ++i) {
char x[] = {kdata[i], '\0'};
ASSERT_TRUE(objArray.AppendElement(Object(x, i)));
objArray.AppendElement(Object(x, i));
}
for (i = 0; i < ArrayLength(kdata); ++i) {
ASSERT_EQ(objArray[i].Str()[0], kdata[i]);
@ -371,7 +371,7 @@ TEST(TArray, test_move_array)
nsTArray<Countable> countableArray;
uint32_t i;
for (i = 0; i < 4; ++i) {
ASSERT_TRUE(countableArray.AppendElement(Countable()));
countableArray.AppendElement(Countable());
}
ASSERT_EQ(Countable::Count(), 8);
@ -417,7 +417,7 @@ TEST(TArray, test_move_array)
nsTArray<Moveable> moveableArray;
for (i = 0; i < 4; ++i) {
ASSERT_TRUE(moveableArray.AppendElement(Moveable()));
moveableArray.AppendElement(Moveable());
}
ASSERT_EQ(Moveable::Count(), 4);
@ -463,7 +463,7 @@ TEST(TArray, test_move_array)
AutoTArray<Moveable, 8> moveableAutoArray;
for (uint32_t i = 0; i < 4; ++i) {
ASSERT_TRUE(moveableAutoArray.AppendElement(Moveable()));
moveableAutoArray.AppendElement(Moveable());
}
ASSERT_EQ(Moveable::Count(), 12);
@ -668,7 +668,7 @@ TEST(TArray, test_string_array)
for (i = 0; i < ArrayLength(kdata); ++i) {
nsCString str;
str.Assign(kdata[i]);
ASSERT_TRUE(strArray.AppendElement(str));
strArray.AppendElement(str);
}
for (i = 0; i < ArrayLength(kdata); ++i) {
ASSERT_EQ(strArray[i].CharAt(0), kdata[i]);
@ -676,7 +676,7 @@ TEST(TArray, test_string_array)
const char kextra[] = "foo bar";
size_t oldLen = strArray.Length();
ASSERT_TRUE(strArray.AppendElement(kextra));
strArray.AppendElement(kextra);
strArray.RemoveElement(kextra);
ASSERT_EQ(oldLen, strArray.Length());