Bug 968520 - Make nsTArray::InsertElementSorted support moves. r=froydnj
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Mon, 08 Jun 2015 13:39:53 -0700
changeset 270980 ca04ee4db747731f83172023a5f1cc41a2d5dece
parent 270979 117d25cbd07c1680aa38a9563e7cfc2d12898870
child 270981 4614a1e2baacaa1cd0010c4dc8a3f2cf74f02b53
push id2738
push userwcosta@mozilla.com
push dateWed, 10 Jun 2015 13:39:02 +0000
reviewersfroydnj
bugs968520
milestone41.0a1
Bug 968520 - Make nsTArray::InsertElementSorted support moves. r=froydnj
xpcom/glue/nsTArray.h
--- a/xpcom/glue/nsTArray.h
+++ b/xpcom/glue/nsTArray.h
@@ -1388,27 +1388,30 @@ public:
   {
     return IndexOfFirstElementGt(aItem, nsDefaultComparator<elem_type, Item>());
   }
 
   // Inserts |aItem| at such an index to guarantee that if the array
   // was previously sorted, it will remain sorted after this
   // insertion.
   template<class Item, class Comparator>
-  elem_type* InsertElementSorted(const Item& aItem, const Comparator& aComp)
+  elem_type* InsertElementSorted(Item&& aItem, const Comparator& aComp)
   {
-    index_type index = IndexOfFirstElementGt(aItem, aComp);
-    return InsertElementAt(index, aItem);
+    index_type index = IndexOfFirstElementGt<Item, Comparator>(aItem, aComp);
+    return InsertElementAt<Item, Alloc>(
+      index, mozilla::Forward<Item>(aItem));
   }
 
   // A variation on the InsertElementSorted method defined above.
   template<class Item>
-  elem_type* InsertElementSorted(const Item& aItem)
+  elem_type* InsertElementSorted(Item&& aItem)
   {
-    return InsertElementSorted(aItem, nsDefaultComparator<elem_type, Item>());
+    nsDefaultComparator<elem_type, Item> comp;
+    return InsertElementSorted<Item, decltype(comp)>(
+      mozilla::Forward<Item>(aItem), comp);
   }
 
   // This method appends elements to the end of this array.
   // @param aArray    The elements to append to this array.
   // @param aArrayLen The number of elements to append to this array.
   // @return          A pointer to the new elements in the array, or null if
   //                  the operation failed due to insufficient memory.
   template<class Item, typename ActualAlloc = Alloc>