Bug 968520 - Add fallible variant of nsTArray::SetLength. r=froydnj

This commit is contained in:
Birunthan Mohanathas 2015-05-18 13:50:34 -07:00
parent 5b2cdf2452
commit a0cd263bb6

View File

@ -1557,16 +1557,23 @@ public:
// @return True if the operation succeeded; false otherwise.
// See also TruncateLength if the new length is guaranteed to be smaller than
// the old.
typename Alloc::ResultType SetLength(size_type aNewLen)
template<typename ActualAlloc = Alloc>
typename ActualAlloc::ResultType SetLength(size_type aNewLen)
{
size_type oldLen = Length();
if (aNewLen > oldLen) {
return Alloc::ConvertBoolToResultType(
InsertElementsAt(oldLen, aNewLen - oldLen) != nullptr);
return ActualAlloc::ConvertBoolToResultType(
InsertElementsAt<ActualAlloc>(oldLen, aNewLen - oldLen) != nullptr);
}
TruncateLength(aNewLen);
return Alloc::ConvertBoolToResultType(true);
return ActualAlloc::ConvertBoolToResultType(true);
}
/* MOZ_WARN_UNUSED_RESULT */
bool SetLength(size_type aNewLen, const mozilla::fallible_t&)
{
return SetLength<FallibleAlloc>(aNewLen);
}
// This method modifies the length of the array, but may only be