Bug 758396 - Let MFBT LinkedList allow const - r=jlebar

This commit is contained in:
Benoit Jacob 2012-05-29 14:44:31 -04:00
parent 3acd5b0163
commit f88c920c2c

View File

@ -125,6 +125,10 @@ public:
{
return next->asT();
}
const T* getNext() const
{
return next->asT();
}
/*
* Get the previous element in the list, or NULL if this is the first element
@ -134,6 +138,10 @@ public:
{
return prev->asT();
}
const T* getPrevious() const
{
return prev->asT();
}
/*
* Insert elem after this element in the list. |this| must be part of a
@ -173,7 +181,7 @@ public:
/*
* Return true if |this| part is of a linked list, and false otherwise.
*/
bool isInList()
bool isInList() const
{
MOZ_ASSERT((next == this) == (prev == this));
return next != this;
@ -208,6 +216,13 @@ private:
return static_cast<T*>(this);
}
const T* asT() const
{
if (isSentinel)
return NULL;
return static_cast<const T*>(this);
}
/*
* Insert elem after this element, but don't check that this element is in
@ -279,6 +294,10 @@ public:
{
return sentinel.getNext();
}
const T* getFirst() const
{
return sentinel.getNext();
}
/*
* Get the last element of the list, or NULL if the list is empty.
@ -287,6 +306,10 @@ public:
{
return sentinel.getPrevious();
}
const T* getLast() const
{
return sentinel.getPrevious();
}
/*
* Get and remove the first element of the list. If the list is empty,
@ -317,7 +340,7 @@ public:
/*
* Return true if the list is empty, or false otherwise.
*/
bool isEmpty()
bool isEmpty() const
{
return !sentinel.isInList();
}
@ -338,16 +361,16 @@ public:
* In a debug build, make sure that the list is sane (no cycles, consistent
* next/prev pointers, only one sentinel). Has no effect in release builds.
*/
void debugAssertIsSane()
void debugAssertIsSane() const
{
#ifdef DEBUG
/*
* Check for cycles in the forward singly-linked list using the
* tortoise/hare algorithm.
*/
for (LinkedListElement<T>* slow = sentinel.next,
* fast1 = sentinel.next->next,
* fast2 = sentinel.next->next->next;
for (const LinkedListElement<T>* slow = sentinel.next,
* fast1 = sentinel.next->next,
* fast2 = sentinel.next->next->next;
slow != sentinel && fast1 != sentinel && fast2 != sentinel;
slow = slow->next,
fast1 = fast2->next,
@ -358,9 +381,9 @@ public:
}
/* Check for cycles in the backward singly-linked list. */
for (LinkedListElement<T>* slow = sentinel.prev,
* fast1 = sentinel.prev->prev,
* fast2 = sentinel.prev->prev->prev;
for (const LinkedListElement<T>* slow = sentinel.prev,
* fast1 = sentinel.prev->prev,
* fast2 = sentinel.prev->prev->prev;
slow != sentinel && fast1 != sentinel && fast2 != sentinel;
slow = slow->prev,
fast1 = fast2->prev,
@ -374,7 +397,7 @@ public:
* Check that |sentinel| is the only node in the list with
* isSentinel == true.
*/
for (LinkedListElement<T>* elem = sentinel.next;
for (const LinkedListElement<T>* elem = sentinel.next;
elem != sentinel;
elem = elem->next) {
@ -382,8 +405,8 @@ public:
}
/* Check that the next/prev pointers match up. */
LinkedListElement<T>* prev = sentinel;
LinkedListElement<T>* cur = sentinel.next;
const LinkedListElement<T>* prev = sentinel;
const LinkedListElement<T>* cur = sentinel.next;
do {
MOZ_ASSERT(cur->prev == prev);
MOZ_ASSERT(prev->next == cur);