From 6ec2ba049c4a1fffa9a24809fef51aff6a5f1e88 Mon Sep 17 00:00:00 2001 From: Mats Palmgren Date: Sun, 14 Oct 2018 18:12:23 +0200 Subject: [PATCH] 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 | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/xpcom/ds/nsTObserverArray.h b/xpcom/ds/nsTObserverArray.h index 91725c244389..18289eb1c41c 100644 --- a/xpcom/ds/nsTObserverArray.h +++ b/xpcom/ds/nsTObserverArray.h @@ -175,13 +175,11 @@ public: // 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 - 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. @@ -196,26 +194,21 @@ public: // 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 - 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 - 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 @@ -228,11 +221,12 @@ public: // 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 - 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.