Bug 867096 - Convert nsTransactionStack from nsDeque to std::deque; r=ehsan

This commit is contained in:
Aryeh Gregor 2013-04-28 14:33:45 +03:00
parent 7ada5be6f3
commit 086a7f60c8
2 changed files with 34 additions and 38 deletions

View File

@ -12,8 +12,7 @@
#include "nscore.h"
nsTransactionStack::nsTransactionStack(nsTransactionStack::Type aType)
: mQue(0)
, mType(aType)
: mType(aType)
{
}
@ -29,71 +28,68 @@ nsTransactionStack::Push(nsTransactionItem *aTransaction)
return;
}
/* nsDeque's Push() method adds new items at the back
* of the deque.
*/
NS_ADDREF(aTransaction);
mQue.Push(aTransaction);
// The stack's bottom is the front of the deque, and the top is the back.
mDeque.push_back(aTransaction);
}
already_AddRefed<nsTransactionItem>
nsTransactionStack::Pop()
{
/* nsDeque is a FIFO, so the top of our stack is actually
* the back of the deque.
*/
return static_cast<nsTransactionItem*> (mQue.Pop());
if (mDeque.empty()) {
return nullptr;
}
nsRefPtr<nsTransactionItem> ret = mDeque.back().forget();
mDeque.pop_back();
return ret.forget();
}
already_AddRefed<nsTransactionItem>
nsTransactionStack::PopBottom()
{
/* nsDeque is a FIFO, so the bottom of our stack is actually
* the front of the deque.
*/
return static_cast<nsTransactionItem*> (mQue.PopFront());
if (mDeque.empty()) {
return nullptr;
}
nsRefPtr<nsTransactionItem> ret = mDeque.front().forget();
mDeque.pop_front();
return ret.forget();
}
already_AddRefed<nsTransactionItem>
nsTransactionStack::Peek()
{
nsRefPtr<nsTransactionItem> transaction;
if (mQue.GetSize()) {
transaction = static_cast<nsTransactionItem*>(mQue.Last());
if (mDeque.empty()) {
return nullptr;
}
return transaction.forget();
nsRefPtr<nsTransactionItem> ret = mDeque.back();
return ret.forget();
}
already_AddRefed<nsTransactionItem>
nsTransactionStack::GetItem(int32_t aIndex)
{
nsRefPtr<nsTransactionItem> transaction;
if (aIndex >= 0 && aIndex < mQue.GetSize()) {
transaction = static_cast<nsTransactionItem*>(mQue.ObjectAt(aIndex));
if (aIndex < 0 || aIndex >= static_cast<int32_t>(mDeque.size())) {
return nullptr;
}
return transaction.forget();
nsRefPtr<nsTransactionItem> ret = mDeque[aIndex];
return ret.forget();
}
void
nsTransactionStack::Clear()
{
nsRefPtr<nsTransactionItem> tx;
do {
tx = mType == FOR_UNDO ? Pop() : PopBottom();
} while (tx);
while (!mDeque.empty()) {
nsRefPtr<nsTransactionItem> tx = mType == FOR_UNDO ? Pop() : PopBottom();
};
}
void
nsTransactionStack::DoTraverse(nsCycleCollectionTraversalCallback &cb)
{
for (int32_t i = 0, qcount = mQue.GetSize(); i < qcount; ++i) {
nsTransactionItem *item =
static_cast<nsTransactionItem*>(mQue.ObjectAt(i));
int32_t size = mDeque.size();
for (int32_t i = 0; i < size; ++i) {
nsTransactionItem* item = mDeque[i];
if (item) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "transaction stack mQue[i]");
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "transaction stack mDeque[i]");
cb.NoteNativeChild(item, NS_CYCLE_COLLECTION_PARTICIPANT(nsTransactionItem));
}
}

View File

@ -6,8 +6,8 @@
#ifndef nsTransactionStack_h__
#define nsTransactionStack_h__
#include "nsCOMPtr.h"
#include "nsDeque.h"
#include <deque>
#include "nsAutoPtr.h"
class nsCycleCollectionTraversalCallback;
class nsTransactionItem;
@ -26,13 +26,13 @@ public:
already_AddRefed<nsTransactionItem> Peek();
already_AddRefed<nsTransactionItem> GetItem(int32_t aIndex);
void Clear();
int32_t GetSize() { return mQue.GetSize(); }
int32_t GetSize() { return mDeque.size(); }
void DoUnlink() { Clear(); }
void DoTraverse(nsCycleCollectionTraversalCallback &cb);
private:
nsDeque mQue;
std::deque<nsRefPtr<nsTransactionItem> > mDeque;
const Type mType;
};