Bug 1277890 - part 0 - add "append already_AddRefed element" API to nsCOMArray; r=erahm
authorNathan Froyd <froydnj@gmail.com>
Tue, 07 Jun 2016 04:10:25 -0400
changeset 376152 24cb98ca61eae5629a28333cbd6e4fa22fc34a4f
parent 376151 6394d8078dfe6a02451a5cc4fbf4ec7666ce5357
child 376153 f7f9ed4d698450254ed5c79798392bb75a43d325
push id20510
push usercholler@mozilla.com
push dateTue, 07 Jun 2016 13:42:30 +0000
reviewerserahm
bugs1277890
milestone49.0a1
Bug 1277890 - part 0 - add "append already_AddRefed element" API to nsCOMArray; r=erahm
xpcom/glue/nsCOMArray.cpp
xpcom/glue/nsCOMArray.h
--- a/xpcom/glue/nsCOMArray.cpp
+++ b/xpcom/glue/nsCOMArray.cpp
@@ -141,16 +141,22 @@ nsCOMArray_base::InsertObjectAt(nsISuppo
 
 void
 nsCOMArray_base::InsertElementAt(uint32_t aIndex, nsISupports* aElement)
 {
   mArray.InsertElementAt(aIndex, aElement);
   NS_IF_ADDREF(aElement);
 }
 
+void
+nsCOMArray_base::InsertElementAt(uint32_t aIndex, already_AddRefed<nsISupports> aElement)
+{
+  mArray.InsertElementAt(aIndex, aElement.take());
+}
+
 bool
 nsCOMArray_base::InsertObjectsAt(const nsCOMArray_base& aObjects, int32_t aIndex)
 {
   if ((uint32_t)aIndex > mArray.Length()) {
     return false;
   }
 
   if (!mArray.InsertElementsAt(aIndex, aObjects.mArray)) {
--- a/xpcom/glue/nsCOMArray.h
+++ b/xpcom/glue/nsCOMArray.h
@@ -57,16 +57,17 @@ protected:
   };
 
   static int nsCOMArrayComparator(const void* aElement1, const void* aElement2,
                                   void* aData);
   void Sort(nsBaseArrayComparatorFunc aFunc, void* aData);
 
   bool InsertObjectAt(nsISupports* aObject, int32_t aIndex);
   void InsertElementAt(uint32_t aIndex, nsISupports* aElement);
+  void InsertElementAt(uint32_t aIndex, already_AddRefed<nsISupports> aElement);
   bool InsertObjectsAt(const nsCOMArray_base& aObjects, int32_t aIndex);
   void InsertElementsAt(uint32_t aIndex, const nsCOMArray_base& aElements);
   void InsertElementsAt(uint32_t aIndex, nsISupports* const* aElements,
                         uint32_t aCount);
   bool ReplaceObjectAt(nsISupports* aObject, int32_t aIndex);
   void ReplaceElementAt(uint32_t aIndex, nsISupports* aElement)
   {
     nsISupports* oldElement = mArray[aIndex];
@@ -76,16 +77,21 @@ protected:
   bool AppendObject(nsISupports* aObject)
   {
     return InsertObjectAt(aObject, Count());
   }
   void AppendElement(nsISupports* aElement)
   {
     InsertElementAt(Length(), aElement);
   }
+  void AppendElement(already_AddRefed<nsISupports> aElement)
+  {
+    InsertElementAt(Length(), mozilla::Move(aElement));
+  }
+
   bool AppendObjects(const nsCOMArray_base& aObjects)
   {
     return InsertObjectsAt(aObjects, Count());
   }
   void AppendElements(const nsCOMArray_base& aElements)
   {
     return InsertElementsAt(Length(), aElements);
   }
@@ -361,16 +367,20 @@ public:
   {
     return nsCOMArray_base::AppendObject(aObject);
   }
   // nsTArray-compatible version
   void AppendElement(T* aElement)
   {
     nsCOMArray_base::AppendElement(aElement);
   }
+  void AppendElement(already_AddRefed<T> aElement)
+  {
+    nsCOMArray_base::AppendElement(mozilla::Move(aElement));
+  }
 
   // append objects, growing the array as necessary
   bool AppendObjects(const nsCOMArray<T>& aObjects)
   {
     return nsCOMArray_base::AppendObjects(aObjects);
   }
   // nsTArray-compatible version
   void AppendElements(const nsCOMArray<T>& aElements)