Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 906912 - Add move constructors to mozilla::LinkedList and mozilla…
Browse files Browse the repository at this point in the history
…::LinkedListElement. r=waldo
  • Loading branch information
jlebar committed Aug 29, 2013
1 parent 8b9dc65 commit 7310669
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions mfbt/LinkedList.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/Move.h"
#include "mozilla/NullPtr.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit 7310669

Please sign in to comment.