Bug 968520 - Add fallible variants of nsTArray::AppendElement. r=froydnj

This commit is contained in:
Birunthan Mohanathas 2015-05-18 13:50:35 -07:00
parent 77989f2ad8
commit d3daa00d55

View File

@ -1448,10 +1448,10 @@ public:
}
// Append a new element, move constructing if possible.
template<class Item>
template<class Item, typename ActualAlloc = Alloc>
elem_type* AppendElement(Item&& aItem)
{
if (!Alloc::Successful(this->template EnsureCapacity<Alloc>(
if (!ActualAlloc::Successful(this->template EnsureCapacity<ActualAlloc>(
Length() + 1, sizeof(elem_type)))) {
return nullptr;
}
@ -1461,6 +1461,14 @@ public:
return elem;
}
template<class Item>
/* MOZ_WARN_UNUSED_RESULT */
elem_type* AppendElement(Item&& aItem,
const mozilla::fallible_t&)
{
return AppendElement<Item, FallibleAlloc>(mozilla::Forward<Item>(aItem));
}
// Append new elements without copy-constructing. This is useful to avoid
// temporaries.
// @return A pointer to the newly appended elements, or null on OOM.
@ -1489,7 +1497,18 @@ public:
// Append a new element without copy-constructing. This is useful to avoid
// temporaries.
// @return A pointer to the newly appended element, or null on OOM.
elem_type* AppendElement() { return AppendElements(1); }
template<typename ActualAlloc = Alloc>
elem_type* AppendElement()
{
return AppendElements<ActualAlloc>(1);
}
template<class Item>
/* MOZ_WARN_UNUSED_RESULT */
elem_type* AppendElement(const mozilla::fallible_t&)
{
return AppendElement<FallibleAlloc>();
}
// Move all elements from another array to the end of this array without
// calling copy constructors or destructors.