зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1626570 - Improve handling of copying arrays in xpcom/. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D73624
This commit is contained in:
Родитель
b8e5abc46a
Коммит
2a7a935311
|
@ -54,7 +54,7 @@ class nsMaybeWeakPtr {
|
|||
// given object to appear in the array once.
|
||||
|
||||
template <class T>
|
||||
class nsMaybeWeakPtrArray : public nsTArray<nsMaybeWeakPtr<T>> {
|
||||
class nsMaybeWeakPtrArray : public CopyableTArray<nsMaybeWeakPtr<T>> {
|
||||
typedef nsTArray<nsMaybeWeakPtr<T>> MaybeWeakArray;
|
||||
|
||||
nsresult SetMaybeWeakPtr(nsMaybeWeakPtr<T>& aRef, T* aElement,
|
||||
|
|
|
@ -410,6 +410,12 @@ class nsTObserverArray : public nsAutoTObserverArray<T, 0> {
|
|||
explicit nsTObserverArray(size_type aCapacity) {
|
||||
base_type::mArray.SetCapacity(aCapacity);
|
||||
}
|
||||
|
||||
nsTObserverArray Clone() const {
|
||||
auto result = nsTObserverArray{};
|
||||
result.mArray.Assign(this->mArray);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, size_t N>
|
||||
|
|
|
@ -146,7 +146,7 @@ class nsTPriorityQueue {
|
|||
mElements[aIndexB] = temp;
|
||||
}
|
||||
|
||||
nsTArray<T> mElements;
|
||||
CopyableTArray<T> mElements;
|
||||
Compare mCompare; // Comparator object
|
||||
};
|
||||
|
||||
|
|
|
@ -939,7 +939,7 @@ void nsPipe::OnPipeException(nsresult aReason, bool aOutputOnly) {
|
|||
|
||||
// OnInputException() can drain the stream and remove it from
|
||||
// mInputList. So iterate over a temp list instead.
|
||||
nsTArray<nsPipeInputStream*> list(mInputList);
|
||||
nsTArray<nsPipeInputStream*> list = mInputList.Clone();
|
||||
for (uint32_t i = 0; i < list.Length(); ++i) {
|
||||
// an output-only exception applies to the input end if the pipe has
|
||||
// zero bytes available.
|
||||
|
|
|
@ -119,7 +119,7 @@ TEST(TArray, int_AppendElements_TArray_Copy)
|
|||
{
|
||||
nsTArray<int> array;
|
||||
|
||||
const nsTArray<int> temp(DummyArray());
|
||||
const nsTArray<int> temp(DummyArray().Clone());
|
||||
int* ptr = array.AppendElements(temp);
|
||||
ASSERT_EQ(&array[0], ptr);
|
||||
ASSERT_EQ(DummyArray(), array);
|
||||
|
@ -138,7 +138,7 @@ TEST(TArray, int_AppendElements_TArray_Copy_Fallible)
|
|||
{
|
||||
nsTArray<int> array;
|
||||
|
||||
const nsTArray<int> temp(DummyArray());
|
||||
const nsTArray<int> temp(DummyArray().Clone());
|
||||
int* ptr = array.AppendElements(temp, fallible);
|
||||
ASSERT_EQ(&array[0], ptr);
|
||||
ASSERT_EQ(DummyArray(), array);
|
||||
|
@ -157,13 +157,13 @@ TEST(TArray, int_AppendElements_TArray_Rvalue)
|
|||
{
|
||||
nsTArray<int> array;
|
||||
|
||||
nsTArray<int> temp(DummyArray());
|
||||
nsTArray<int> temp(DummyArray().Clone());
|
||||
int* ptr = array.AppendElements(std::move(temp));
|
||||
ASSERT_EQ(&array[0], ptr);
|
||||
ASSERT_EQ(DummyArray(), array);
|
||||
ASSERT_TRUE(temp.IsEmpty());
|
||||
|
||||
temp = DummyArray();
|
||||
temp = DummyArray().Clone();
|
||||
ptr = array.AppendElements(std::move(temp));
|
||||
ASSERT_EQ(&array[DummyArray().Length()], ptr);
|
||||
nsTArray<int> expected;
|
||||
|
@ -177,13 +177,13 @@ TEST(TArray, int_AppendElements_TArray_Rvalue_Fallible)
|
|||
{
|
||||
nsTArray<int> array;
|
||||
|
||||
nsTArray<int> temp(DummyArray());
|
||||
nsTArray<int> temp(DummyArray().Clone());
|
||||
int* ptr = array.AppendElements(std::move(temp), fallible);
|
||||
ASSERT_EQ(&array[0], ptr);
|
||||
ASSERT_EQ(DummyArray(), array);
|
||||
ASSERT_TRUE(temp.IsEmpty());
|
||||
|
||||
temp = DummyArray();
|
||||
temp = DummyArray().Clone();
|
||||
ptr = array.AppendElements(std::move(temp), fallible);
|
||||
ASSERT_EQ(&array[DummyArray().Length()], ptr);
|
||||
nsTArray<int> expected;
|
||||
|
@ -239,7 +239,7 @@ TEST(TArray, AppendElementsSpan)
|
|||
{
|
||||
nsTArray<int> array;
|
||||
|
||||
nsTArray<int> temp(DummyArray());
|
||||
nsTArray<int> temp(DummyArray().Clone());
|
||||
Span<int> span = temp;
|
||||
array.AppendElements(span);
|
||||
ASSERT_EQ(DummyArray(), array);
|
||||
|
@ -489,7 +489,7 @@ TEST(TArray, int_Assign)
|
|||
|
||||
TEST(TArray, int_AssignmentOperatorSelfAssignment)
|
||||
{
|
||||
nsTArray<int> array;
|
||||
CopyableTArray<int> array;
|
||||
array = DummyArray();
|
||||
|
||||
array = *&array;
|
||||
|
|
|
@ -35,7 +35,7 @@ inline bool operator<(const nsCOMPtr<T>& lhs, const nsCOMPtr<T>& rhs) {
|
|||
template <class ElementType>
|
||||
static bool test_basic_array(ElementType* data, size_t dataLen,
|
||||
const ElementType& extra) {
|
||||
nsTArray<ElementType> ary;
|
||||
CopyableTArray<ElementType> ary;
|
||||
const nsTArray<ElementType>& cary = ary;
|
||||
|
||||
ary.AppendElements(data, dataLen);
|
||||
|
@ -143,7 +143,7 @@ static bool test_basic_array(ElementType* data, size_t dataLen,
|
|||
[]() { return false; }))
|
||||
return false;
|
||||
|
||||
nsTArray<ElementType> copy(ary);
|
||||
nsTArray<ElementType> copy(ary.Clone());
|
||||
if (!(ary == copy)) return false;
|
||||
for (i = 0; i < copy.Length(); ++i) {
|
||||
if (ary[i] != copy[i]) return false;
|
||||
|
@ -380,7 +380,7 @@ TEST(TArray, test_move_array)
|
|||
|
||||
ASSERT_EQ(Countable::Count(), 8);
|
||||
|
||||
nsTArray<Countable> copyCountableArray(constRefCountableArray);
|
||||
nsTArray<Countable> copyCountableArray(constRefCountableArray.Clone());
|
||||
|
||||
ASSERT_EQ(Countable::Count(), 12);
|
||||
|
||||
|
@ -426,7 +426,7 @@ TEST(TArray, test_move_array)
|
|||
|
||||
ASSERT_EQ(Moveable::Count(), 4);
|
||||
|
||||
nsTArray<Moveable> copyMoveableArray(constRefMoveableArray);
|
||||
nsTArray<Moveable> copyMoveableArray(constRefMoveableArray.Clone());
|
||||
|
||||
ASSERT_EQ(Moveable::Count(), 8);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче