mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 1494745 part 6 - Make ns[Auto]TObserverArray methods that insert/append an Item return void since they're infallible. r=bz
This commit is contained in:
parent
faeddacfac
commit
6ec2ba049c
@ -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<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.
|
||||
@ -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<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
|
||||
@ -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<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.
|
||||
|
Loading…
Reference in New Issue
Block a user