Bug 1494745 part 6 - Make ns[Auto]TObserverArray methods that insert/append an Item return void since they're infallible. r=bz
authorMats Palmgren <mats@mozilla.com>
Sun, 14 Oct 2018 18:12:23 +0200
changeset 499625 2b7fce8c4f926662732fae0deaf857121810f1ab
parent 499624 74198da29da55fc32fb6c7b102bda55d16058ae6
child 499626 3aca49b2df240e86d5b164feb18575681c818c63
child 499636 f8d848fba55e9c0aa67e47eaecf1ddd1dcf4d71d
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1494745
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1494745 part 6 - Make ns[Auto]TObserverArray methods that insert/append an Item return void since they're infallible. r=bz
xpcom/ds/nsTObserverArray.h
--- a/xpcom/ds/nsTObserverArray.h
+++ b/xpcom/ds/nsTObserverArray.h
@@ -170,74 +170,68 @@ public:
 
   //
   // Mutation methods
   //
 
   // Insert a given element at the given index.
   // @param aIndex The index at which to insert item.
   // @param aItem  The item to insert,
-  // @return A pointer to the newly inserted element, or a null on DOM
   template<class Item>
-  elem_type* InsertElementAt(index_type aIndex, const Item& aItem)
+  void InsertElementAt(index_type aIndex, const Item& aItem)
   {
-    elem_type* item = mArray.InsertElementAt(aIndex, aItem);
+    mArray.InsertElementAt(aIndex, aItem);
     AdjustIterators(aIndex, 1);
-    return item;
   }
 
   // Same as above but without copy constructing.
   // This is useful to avoid temporaries.
   elem_type* InsertElementAt(index_type aIndex)
   {
     elem_type* item = mArray.InsertElementAt(aIndex);
     AdjustIterators(aIndex, 1);
     return item;
   }
 
   // Prepend an element to the array unless it already exists in the array.
   // 'operator==' must be defined for elem_type.
   // @param aItem The item to prepend.
-  // @return true if the element was found, or inserted successfully.
   template<class Item>
-  bool PrependElementUnlessExists(const Item& aItem)
+  void PrependElementUnlessExists(const Item& aItem)
   {
-    if (Contains(aItem)) {
-      return true;
+    if (!Contains(aItem)) {
+      mArray.InsertElementAt(0, aItem);
+      AdjustIterators(0, 1);
     }
-
-    bool inserted = mArray.InsertElementAt(0, aItem) != nullptr;
-    AdjustIterators(0, 1);
-    return inserted;
   }
 
   // Append an element to the array.
   // @param aItem The item to append.
-  // @return A pointer to the newly appended element, or null on OOM.
   template<class Item>
-  elem_type* AppendElement(const Item& aItem)
+  void AppendElement(const Item& aItem)
   {
-    return mArray.AppendElement(aItem);
+    mArray.AppendElement(aItem);
   }
 
   // Same as above, but without copy-constructing. This is useful to avoid
   // temporaries.
   elem_type* AppendElement()
   {
     return mArray.AppendElement();
   }
 
   // Append an element to the array unless it already exists in the array.
   // 'operator==' must be defined for elem_type.
   // @param aItem The item to append.
-  // @return true if the element was found, or inserted successfully.
   template<class Item>
-  bool AppendElementUnlessExists(const Item& aItem)
+  void AppendElementUnlessExists(const Item& aItem)
   {
-    return Contains(aItem) || AppendElement(aItem) != nullptr;
+    if (!Contains(aItem)) {
+      mArray.AppendElement(aItem);
+    }
   }
 
   // Remove an element from the array.
   // @param aIndex The index of the item to remove.
   void RemoveElementAt(index_type aIndex)
   {
     NS_ASSERTION(aIndex < mArray.Length(), "invalid index");
     mArray.RemoveElementAt(aIndex);