Bug 867096 - Convert nsTransactionStack from nsDeque to std::deque; r=ehsan
authorAryeh Gregor <ayg@aryeh.name>
Sun, 28 Apr 2013 14:33:45 +0300
changeset 142197 5971dba36391e2fbfcea5555ad2b22f19bcfe7f6
parent 142196 bce4dc724d4a92605c342d6c5065941cc0492ac1
child 142198 c97a67b4ec08925d4aa96215f9a96c2efc8f52e0
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs867096
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 867096 - Convert nsTransactionStack from nsDeque to std::deque; r=ehsan
editor/txmgr/src/nsTransactionStack.cpp
editor/txmgr/src/nsTransactionStack.h
--- a/editor/txmgr/src/nsTransactionStack.cpp
+++ b/editor/txmgr/src/nsTransactionStack.cpp
@@ -7,94 +7,90 @@
 #include "nsCOMPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsISupportsUtils.h"
 #include "nsTransactionItem.h"
 #include "nsTransactionStack.h"
 #include "nscore.h"
 
 nsTransactionStack::nsTransactionStack(nsTransactionStack::Type aType)
-  : mQue(0)
-  , mType(aType)
+  : mType(aType)
 {
 }
 
 nsTransactionStack::~nsTransactionStack()
 {
   Clear();
 }
 
 void
 nsTransactionStack::Push(nsTransactionItem *aTransaction)
 {
   if (!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));
     }
   }
 }
--- a/editor/txmgr/src/nsTransactionStack.h
+++ b/editor/txmgr/src/nsTransactionStack.h
@@ -1,18 +1,18 @@
 /* -*- 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 "nsCOMPtr.h"
-#include "nsDeque.h"
+#include <deque>
+#include "nsAutoPtr.h"
 
 class nsCycleCollectionTraversalCallback;
 class nsTransactionItem;
 
 class nsTransactionStack
 {
 public:
   enum Type { FOR_UNDO, FOR_REDO };
@@ -21,19 +21,19 @@ public:
   ~nsTransactionStack();
 
   void Push(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() { 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;
 };
 
 #endif // nsTransactionStack_h__