Bug 1293666 - Add initializer_list ctor to AutoTArray. r=froydnj
MozReview-Commit-ID: 8ORBttWN2Rj
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -4447,18 +4447,17 @@ nsDocShell::RemoveFromSessionHistory()
}
}
if (!internalHistory) {
return NS_OK;
}
int32_t index = 0;
sessionHistory->GetIndex(&index);
- AutoTArray<uint64_t, 16> ids;
- ids.AppendElement(mHistoryID);
+ AutoTArray<uint64_t, 16> ids({mHistoryID});
internalHistory->RemoveEntries(ids, index);
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::SetCreatedDynamically(bool aDynamic)
{
mDynamicallyCreated = aDynamic;
--- a/dom/base/File.cpp
+++ b/dom/base/File.cpp
@@ -250,18 +250,17 @@ Blob::ToFile()
}
return file.forget();
}
already_AddRefed<File>
Blob::ToFile(const nsAString& aName, ErrorResult& aRv) const
{
- AutoTArray<RefPtr<BlobImpl>, 1> blobImpls;
- blobImpls.AppendElement(mImpl);
+ AutoTArray<RefPtr<BlobImpl>, 1> blobImpls({mImpl});
nsAutoString contentType;
mImpl->GetType(contentType);
RefPtr<MultipartBlobImpl> impl =
MultipartBlobImpl::Create(blobImpls, aName, contentType, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
--- a/xpcom/glue/nsTArray.h
+++ b/xpcom/glue/nsTArray.h
@@ -2211,16 +2211,22 @@ public:
template<typename Allocator>
explicit AutoTArray(nsTArray_Impl<elem_type, Allocator>&& aOther)
{
Init();
this->SwapElements(aOther);
}
+ MOZ_IMPLICIT AutoTArray(std::initializer_list<E> aIL)
+ {
+ Init();
+ this->AppendElements(aIL.begin(), aIL.size());
+ }
+
self_type& operator=(const self_type& aOther)
{
base_type::operator=(aOther);
return *this;
}
template<typename Allocator>
self_type& operator=(const nsTArray_Impl<elem_type, Allocator>& aOther)