Bug 906912 - Add move constructors to mozilla::LinkedList and mozilla::LinkedListElement. r=waldo

--HG--
extra : rebase_source : 864a78505421e129a4553634e08a7f9fc343d7d1
This commit is contained in:
Justin Lebar 2013-08-29 11:54:14 -07:00
parent 66f7416cab
commit 6bc3732c09

View File

@ -58,6 +58,7 @@
#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/Move.h"
#include "mozilla/NullPtr.h"
#ifdef __cplusplus
@ -116,6 +117,36 @@ class LinkedListElement
isSentinel(false)
{ }
LinkedListElement(LinkedListElement<T>&& other)
: isSentinel(other.isSentinel)
{
if (!other.isInList()) {
next = this;
prev = this;
return;
}
MOZ_ASSERT(other.next->prev == &other);
MOZ_ASSERT(other.prev->next == &other);
/*
* Initialize |this| with |other|'s prev/next pointers, and adjust those
* element to point to this one.
*/
next = other.next;
prev = other.prev;
next->prev = this;
prev->next = this;
/*
* Adjust |other| so it doesn't think it's in a list. This makes it
* safely destructable.
*/
other.next = &other;
other.prev = &other;
}
~LinkedListElement() {
if (!isSentinel && isInList())
remove();
@ -265,6 +296,10 @@ class LinkedList
public:
LinkedList() : sentinel(LinkedListElement<T>::NODE_KIND_SENTINEL) { }
LinkedList(LinkedList<T>&& other)
: sentinel(mozilla::Move(other.sentinel))
{ }
~LinkedList() {
MOZ_ASSERT(isEmpty());
}