зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1310547 - Add removeAndGetNext/Previous methods to LinkedList (r=froydnj)
This commit is contained in:
Родитель
c0d229e060
Коммит
4c8471eb15
|
@ -250,6 +250,30 @@ public:
|
|||
Traits::exitList(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove this element from the list containing it. Returns a pointer to the
|
||||
* element that follows this element (before it was removed). This method
|
||||
* asserts if the element does not belong to a list.
|
||||
*/
|
||||
ClientType removeAndGetNext()
|
||||
{
|
||||
ClientType r = getNext();
|
||||
remove();
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove this element from the list containing it. Returns a pointer to the
|
||||
* previous element in the containing list (before the removal). This method
|
||||
* asserts if the element does not belong to a list.
|
||||
*/
|
||||
ClientType removeAndGetPrevious()
|
||||
{
|
||||
ClientType r = getPrevious();
|
||||
remove();
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
* Identical to remove(), but also asserts in debug builds that this element
|
||||
* is in aList.
|
||||
|
|
|
@ -156,6 +156,24 @@ TestMove()
|
|||
list3.clear();
|
||||
}
|
||||
|
||||
static void
|
||||
TestRemoveAndGet()
|
||||
{
|
||||
LinkedList<SomeClass> list;
|
||||
|
||||
SomeClass one(1), two(2), three(3);
|
||||
list.insertBack(&one);
|
||||
list.insertBack(&two);
|
||||
list.insertBack(&three);
|
||||
{ unsigned int check[] { 1, 2, 3 }; CheckListValues(list, check); }
|
||||
|
||||
MOZ_RELEASE_ASSERT(two.removeAndGetNext() == &three);
|
||||
{ unsigned int check[] { 1, 3 }; CheckListValues(list, check); }
|
||||
|
||||
MOZ_RELEASE_ASSERT(three.removeAndGetPrevious() == &one);
|
||||
{ unsigned int check[] { 1 }; CheckListValues(list, check); }
|
||||
}
|
||||
|
||||
struct PrivateClass : private LinkedListElement<PrivateClass> {
|
||||
friend class mozilla::LinkedList<PrivateClass>;
|
||||
friend class mozilla::LinkedListElement<PrivateClass>;
|
||||
|
@ -244,6 +262,7 @@ main()
|
|||
TestList();
|
||||
TestPrivate();
|
||||
TestMove();
|
||||
TestRemoveAndGet();
|
||||
TestRefPtrList();
|
||||
return 0;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче