зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1645447 - Add ForwardIterator::Remove and EndLimitedIterator::Remove functions. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D79512
This commit is contained in:
Родитель
87a2eb06f5
Коммит
08dfb8127e
|
@ -332,6 +332,13 @@ class nsAutoTObserverArray : protected nsTObserverArray_base {
|
|||
NS_ASSERTION(HasMore(), "iterating beyond end of array");
|
||||
return base_type::mArray.Elements()[base_type::mPosition++];
|
||||
}
|
||||
|
||||
// Removes the element at the current iterator position.
|
||||
// (the last element returned from |GetNext()|)
|
||||
// This will not affect the next call to |GetNext()|
|
||||
void Remove() {
|
||||
return base_type::mArray.RemoveElementAt(base_type::mPosition - 1);
|
||||
}
|
||||
};
|
||||
|
||||
// EndLimitedIterator works like ForwardIterator, but will not iterate new
|
||||
|
@ -357,6 +364,13 @@ class nsAutoTObserverArray : protected nsTObserverArray_base {
|
|||
return base_type::mArray.Elements()[base_type::mPosition++];
|
||||
}
|
||||
|
||||
// Removes the element at the current iterator position.
|
||||
// (the last element returned from |GetNext()|)
|
||||
// This will not affect the next call to |GetNext()|
|
||||
void Remove() {
|
||||
return base_type::mArray.RemoveElementAt(base_type::mPosition - 1);
|
||||
}
|
||||
|
||||
private:
|
||||
ForwardIterator mEnd;
|
||||
};
|
||||
|
|
|
@ -30,6 +30,7 @@ typedef nsTObserverArray<int> IntArray;
|
|||
<< "During test " << testNum << ", iterator finished too early"; \
|
||||
} while (0)
|
||||
|
||||
// XXX Split this up into independent test cases
|
||||
TEST(ObserverArray, Tests)
|
||||
{
|
||||
IntArray arr;
|
||||
|
@ -156,6 +157,24 @@ TEST(ObserverArray, Tests)
|
|||
*/
|
||||
}
|
||||
|
||||
TEST(ObserverArray, ForwardIterator_Remove)
|
||||
{
|
||||
static const int expected[] = {3, 4};
|
||||
|
||||
IntArray arr;
|
||||
arr.AppendElement(3);
|
||||
arr.AppendElement(4);
|
||||
|
||||
size_t count = 0;
|
||||
for (auto iter = IntArray::ForwardIterator{arr}; iter.HasMore();) {
|
||||
const int next = iter.GetNext();
|
||||
iter.Remove();
|
||||
|
||||
ASSERT_EQ(expected[count++], next);
|
||||
}
|
||||
ASSERT_EQ(2u, count);
|
||||
}
|
||||
|
||||
TEST(ObserverArray, RangeBasedFor_Value_Forward_NonEmpty)
|
||||
{
|
||||
IntArray arr;
|
||||
|
@ -550,3 +569,5 @@ TEST(ObserverArray, RangeBasedFor_Reference_NonObserving_NonEmpty)
|
|||
EXPECT_EQ(2u, iterations);
|
||||
EXPECT_EQ(7, sum);
|
||||
}
|
||||
|
||||
// TODO add tests for EndLimitedIterator
|
||||
|
|
Загрузка…
Ссылка в новой задаче