Bug 570417 - All content iterators need to take part in cycle collection; r=jst
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 08 Jun 2010 00:31:44 -0400
changeset 43411 961e152b8b7bb57082da89fe20e07b8f0e1a48e8
parent 43410 af44e6577313004cac2f95ed0924f43dbecfae5f
child 43412 3869cf687c267fbfa19be529ed54b36540498c0b
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst
bugs570417
milestone1.9.3a5pre
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 570417 - All content iterators need to take part in cycle collection; r=jst
content/base/src/nsContentIterator.cpp
--- a/content/base/src/nsContentIterator.cpp
+++ b/content/base/src/nsContentIterator.cpp
@@ -117,17 +117,17 @@ NodeIsInTraversalRange(nsINode *aNode, P
  *  A simple iterator class for traversing the content in "close tag" order
  */
 class nsContentIterator : public nsIContentIterator //, public nsIEnumerator
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_CLASS(nsContentIterator)
 
-  nsContentIterator();
+  explicit nsContentIterator(PRBool aPre);
   virtual ~nsContentIterator();
 
   // nsIContentIterator interface methods ------------------------------
 
   virtual nsresult Init(nsINode* aRoot);
 
   virtual nsresult Init(nsIDOMRange* aRange);
   virtual nsresult Init(nsIRange* aRange);
@@ -203,48 +203,36 @@ private:
 
   // no copy's or assigns  FIX ME
   nsContentIterator(const nsContentIterator&);
   nsContentIterator& operator=(const nsContentIterator&);
 
 };
 
 
-/*
- *  A simple iterator class for traversing the content in "open tag" order
- */
-
-class nsPreContentIterator : public nsContentIterator
-{
-public:
-  nsPreContentIterator() { mPre = PR_TRUE; }
-};
-
-
-
 /******************************************************
  * repository cruft
  ******************************************************/
 
 nsresult NS_NewContentIterator(nsIContentIterator** aInstancePtrResult)
 {
-  nsContentIterator * iter = new nsContentIterator();
+  nsContentIterator * iter = new nsContentIterator(PR_FALSE);
   if (!iter) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   NS_ADDREF(*aInstancePtrResult = iter);
 
   return NS_OK;
 }
 
 
 nsresult NS_NewPreContentIterator(nsIContentIterator** aInstancePtrResult)
 {
-  nsContentIterator * iter = new nsPreContentIterator();
+  nsContentIterator * iter = new nsContentIterator(PR_TRUE);
   if (!iter) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   NS_ADDREF(*aInstancePtrResult = iter);
 
   return NS_OK;
 }
@@ -268,19 +256,19 @@ NS_IMPL_CYCLE_COLLECTION_4(nsContentIter
                            mFirst,
                            mLast,
                            mCommonParent)
 
 /******************************************************
  * constructor/destructor
  ******************************************************/
 
-nsContentIterator::nsContentIterator() :
+nsContentIterator::nsContentIterator(PRBool aPre) :
   // don't need to explicitly initialize |nsCOMPtr|s, they will automatically be NULL
-  mCachedIndex(0), mIsDone(PR_FALSE), mPre(PR_FALSE)
+  mCachedIndex(0), mIsDone(PR_FALSE), mPre(aPre)
 {
 }
 
 
 nsContentIterator::~nsContentIterator()
 {
 }
 
@@ -1177,19 +1165,22 @@ nsContentIterator::GetCurrentNode()
 
 
 /*
  *  A simple iterator class for traversing the content in "top subtree" order
  */
 class nsContentSubtreeIterator : public nsContentIterator 
 {
 public:
-  nsContentSubtreeIterator() {}
+  nsContentSubtreeIterator() : nsContentIterator(PR_FALSE) {}
   virtual ~nsContentSubtreeIterator() {}
 
+  NS_DECL_ISUPPORTS_INHERITED
+  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsContentSubtreeIterator, nsContentIterator)
+
   // nsContentIterator overrides ------------------------------
 
   virtual nsresult Init(nsINode* aRoot);
 
   virtual nsresult Init(nsIDOMRange* aRange);
   virtual nsresult Init(nsIRange* aRange);
 
   virtual void Next();
@@ -1219,16 +1210,30 @@ protected:
   nsAutoTArray<nsIContent*, 8> mStartNodes;
   nsAutoTArray<PRInt32, 8>     mStartOffsets;
 #endif
 
   nsAutoTArray<nsIContent*, 8> mEndNodes;
   nsAutoTArray<PRInt32, 8>     mEndOffsets;
 };
 
+NS_IMPL_ADDREF_INHERITED(nsContentSubtreeIterator, nsContentIterator)
+NS_IMPL_RELEASE_INHERITED(nsContentSubtreeIterator, nsContentIterator)
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsContentSubtreeIterator)
+NS_INTERFACE_MAP_END_INHERITING(nsContentIterator)
+
+NS_IMPL_CYCLE_COLLECTION_CLASS(nsContentSubtreeIterator)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsContentSubtreeIterator, nsContentIterator)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRange)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsContentSubtreeIterator, nsContentIterator)
+  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRange)
+NS_IMPL_CYCLE_COLLECTION_UNLINK_END
+
 nsresult NS_NewContentSubtreeIterator(nsIContentIterator** aInstancePtrResult);
 
 
 
 
 /******************************************************
  * repository cruft
  ******************************************************/