Bug 810094 - make nsXMLContentSink::mDocElement a COMptr. r=hsivonen
authorAndrew McCreight <amccreight@mozilla.com>
Mon, 12 Nov 2012 09:43:02 -0800
changeset 113003 33d32f170ff2a32a599440473dbf661e12221b70
parent 113002 08fd9aa0d6e1d9e1493eed9013422bbcd3dcfb60
child 113004 82cb8e969e0c40855a6d7b0e3f2003799323e9de
push id23847
push userphilringnalda@gmail.com
push dateTue, 13 Nov 2012 05:07:25 +0000
treeherdermozilla-central@1b0226622e94 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsivonen
bugs810094
milestone19.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 810094 - make nsXMLContentSink::mDocElement a COMptr. r=hsivonen
content/xml/document/src/nsXMLContentSink.cpp
content/xml/document/src/nsXMLContentSink.h
--- a/content/xml/document/src/nsXMLContentSink.cpp
+++ b/content/xml/document/src/nsXMLContentSink.cpp
@@ -96,17 +96,16 @@ NS_NewXMLContentSink(nsIXMLContentSink**
 nsXMLContentSink::nsXMLContentSink()
   : mConstrainSize(true),
     mPrettyPrintXML(true)
 {
 }
 
 nsXMLContentSink::~nsXMLContentSink()
 {
-  NS_IF_RELEASE(mDocElement);
   if (mText) {
     PR_Free(mText);  //  Doesn't null out, unlike PR_FREEIF
   }
 }
 
 nsresult
 nsXMLContentSink::Init(nsIDocument* aDoc,
                        nsIURI* aURI,
@@ -139,17 +138,17 @@ NS_INTERFACE_MAP_END_INHERITING(nsConten
 NS_IMPL_ADDREF_INHERITED(nsXMLContentSink, nsContentSink)
 NS_IMPL_RELEASE_INHERITED(nsXMLContentSink, nsContentSink)
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsXMLContentSink)
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXMLContentSink,
                                                   nsContentSink)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCurrentHead)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mDocElement)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocElement)
   for (uint32_t i = 0, count = tmp->mContentStack.Length(); i < count; i++) {
     const StackNode& node = tmp->mContentStack.ElementAt(i);
     cb.NoteXPCOMChild(node.mContent);
   }
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 // nsIContentSink
 NS_IMETHODIMP
@@ -922,17 +921,16 @@ nsXMLContentSink::SetDocElement(int32_t 
       mDocument->ScriptLoader()->SetEnabled(false);
       if (mCSSLoader) {
         mCSSLoader->SetEnabled(false);
       }
     }        
   }
 
   mDocElement = aContent;
-  NS_ADDREF(mDocElement);
   nsresult rv = mDocument->AppendChildTo(mDocElement, NotifyForDocElement());
   if (NS_FAILED(rv)) {
     // If we return false here, the caller will bail out because it won't
     // find a parent content node to append to, which is fine.
     return false;
   }
 
   if (aTagName == nsGkAtoms::html &&
@@ -1396,17 +1394,17 @@ nsXMLContentSink::ReportError(const PRUn
     for (;;) {
       nsCOMPtr<nsIDOMNode> child, dummy;
       node->GetLastChild(getter_AddRefs(child));
       if (!child)
         break;
       node->RemoveChild(child, getter_AddRefs(dummy));
     }
   }
-  NS_IF_RELEASE(mDocElement); 
+  mDocElement = nullptr;
 
   // Clear any buffered-up text we have.  It's enough to set the length to 0.
   // The buffer itself is allocated when we're created and deleted in our
   // destructor, so don't mess with it.
   mTextLength = 0;
 
   if (mXSLTProcessor) {
     // Get rid of the XSLT processor.
--- a/content/xml/document/src/nsXMLContentSink.h
+++ b/content/xml/document/src/nsXMLContentSink.h
@@ -158,17 +158,17 @@ protected:
   nsresult HandleStartElement(const PRUnichar *aName, const PRUnichar **aAtts, 
                               uint32_t aAttsCount, int32_t aIndex, 
                               uint32_t aLineNumber,
                               bool aInterruptable);
   nsresult HandleEndElement(const PRUnichar *aName, bool aInterruptable);
   nsresult HandleCharacterData(const PRUnichar *aData, uint32_t aLength,
                                bool aInterruptable);
 
-  nsIContent*      mDocElement;
+  nsCOMPtr<nsIContent> mDocElement;
   nsCOMPtr<nsIContent> mCurrentHead;  // When set, we're in an XHTML <haed>
   PRUnichar*       mText;
 
   XMLContentSinkState mState;
 
   int32_t mTextLength;
   int32_t mTextSize;