gecko-dev/editor/txmgr/nsTransactionStack.h
Nathan Froyd 7578babdd1 Bug 1254618 - modify nsTransactionStack to use nsDeque rather than std::deque; r=ehsan
Using std::deque here causes problems for libc++ builds; TestTXMgr on
OSX 10.6 opt times out when libc++'d std::deque is used.  Running the
test locally shows that the test process consumes gigabytes (!) of
memory and is thus reduced to swapping, rather than making any progress.
libc++'s std::deque also appears to be slightly slower in said test that
even OSX libstdc++'s std::deque.  (Admittedly, this test is artificial.)

Let's sidestep the slowness of libc++'s std::deque by rewriting
nsTransactionStack to use nsDeque rather than std::deque.  Not only does
this change enable OSX 10.6 tests to pass, it also makes TestTXMgr
significantly faster in opt builds: TestTXMgr is anywhere from 25-60%
faster (depending on the platform) than when using std::deque from
libstdc++ or libc++.
2016-03-07 20:12:07 -05:00

41 lines
1.2 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsTransactionStack_h__
#define nsTransactionStack_h__
#include "nsDeque.h"
#include "nsAutoPtr.h"
class nsCycleCollectionTraversalCallback;
class nsTransactionItem;
class nsTransactionStack : private nsDeque
{
public:
enum Type { FOR_UNDO, FOR_REDO };
explicit nsTransactionStack(Type aType);
~nsTransactionStack();
void Push(nsTransactionItem *aTransactionItem);
void Push(already_AddRefed<nsTransactionItem> aTransactionItem);
already_AddRefed<nsTransactionItem> Pop();
already_AddRefed<nsTransactionItem> PopBottom();
already_AddRefed<nsTransactionItem> Peek();
already_AddRefed<nsTransactionItem> GetItem(int32_t aIndex);
void Clear();
int32_t GetSize() const { return static_cast<int32_t>(nsDeque::GetSize()); }
bool IsEmpty() const { return GetSize() == 0; }
void DoUnlink() { Clear(); }
void DoTraverse(nsCycleCollectionTraversalCallback &cb);
private:
const Type mType;
};
#endif // nsTransactionStack_h__