Bug 1293666 - Add initializer_list ctor to AutoTArray. r=froydnj draft
authorAndrew McCreight <continuation@gmail.com>
Tue, 09 Aug 2016 07:21:26 -0700
changeset 398833 2ed704eceb0e4ab2bed25976cf01d5902d72a3f8
parent 398609 3d8a310ac7c01a961c725ae44f45d26d80fc78b8
child 527766 846af401035de882c54d7150e2e3fc9a9b664b62
push id25649
push userbmo:continuation@gmail.com
push dateTue, 09 Aug 2016 21:07:30 +0000
reviewersfroydnj
bugs1293666
milestone51.0a1
Bug 1293666 - Add initializer_list ctor to AutoTArray. r=froydnj MozReview-Commit-ID: 8ORBttWN2Rj
docshell/base/nsDocShell.cpp
dom/base/File.cpp
xpcom/glue/nsTArray.h
--- 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)