From 538dcc1d3927f954e9f6c020a5baa43bd9f93074 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Mon, 18 May 2015 13:50:35 -0700 Subject: [PATCH] Bug 968520 - Add fallible variants of nsTArray::AppendElements. r=froydnj --- xpcom/glue/nsTArray.h | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/xpcom/glue/nsTArray.h b/xpcom/glue/nsTArray.h index 296f33dad575..817dd27753ae 100644 --- a/xpcom/glue/nsTArray.h +++ b/xpcom/glue/nsTArray.h @@ -1411,10 +1411,10 @@ public: // @param aArrayLen The number of elements to append to this array. // @return A pointer to the new elements in the array, or null if // the operation failed due to insufficient memory. - template + template elem_type* AppendElements(const Item* aArray, size_type aArrayLen) { - if (!Alloc::Successful(this->template EnsureCapacity( + if (!ActualAlloc::Successful(this->template EnsureCapacity( Length() + aArrayLen, sizeof(elem_type)))) { return nullptr; } @@ -1424,11 +1424,27 @@ public: return Elements() + len; } + template + /* MOZ_WARN_UNUSED_RESULT */ + elem_type* AppendElements(const Item* aArray, size_type aArrayLen, + const mozilla::fallible_t&) + { + return AppendElements(aArray, aArrayLen); + } + // A variation on the AppendElements method defined above. - template + template elem_type* AppendElements(const nsTArray_Impl& aArray) { - return AppendElements(aArray.Elements(), aArray.Length()); + return AppendElements(aArray.Elements(), aArray.Length()); + } + + template + /* MOZ_WARN_UNUSED_RESULT */ + elem_type* AppendElements(const nsTArray_Impl& aArray, + const mozilla::fallible_t&) + { + return AppendElements(aArray); } // Append a new element, move constructing if possible. @@ -1448,9 +1464,9 @@ public: // Append new elements without copy-constructing. This is useful to avoid // temporaries. // @return A pointer to the newly appended elements, or null on OOM. - elem_type* AppendElements(size_type aCount) - { - if (!Alloc::Successful(this->template EnsureCapacity( + template + elem_type* AppendElements(size_type aCount) { + if (!ActualAlloc::Successful(this->template EnsureCapacity( Length() + aCount, sizeof(elem_type)))) { return nullptr; } @@ -1463,6 +1479,13 @@ public: return elems; } + /* MOZ_WARN_UNUSED_RESULT */ + elem_type* AppendElements(size_type aCount, + const mozilla::fallible_t&) + { + return AppendElements(aCount); + } + // 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.