Bug 867092 - Don't implicitly convert to already_AddRefed in nsNodeInfoManager; r=bz
authorAryeh Gregor <ayg@aryeh.name>
Fri, 26 Apr 2013 14:51:07 +0300
changeset 142057 886b8ddf0611b87def2af695a3e2045db7d343c1
parent 142056 357af4877abd85e42907dee3b07aedabb0187e62
child 142058 74c713a90a7bbeeada962980b791d29b31e6bcaa
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)
reviewersbz
bugs867092
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 867092 - Don't implicitly convert to already_AddRefed in nsNodeInfoManager; r=bz
content/base/src/nsNodeInfoManager.cpp
--- a/content/base/src/nsNodeInfoManager.cpp
+++ b/content/base/src/nsNodeInfoManager.cpp
@@ -326,61 +326,72 @@ nsNodeInfoManager::GetNodeInfo(const nsA
   }
 
   return GetNodeInfo(aName, aPrefix, nsid, aNodeType, aNodeInfo);
 }
 
 already_AddRefed<nsINodeInfo>
 nsNodeInfoManager::GetTextNodeInfo()
 {
+  nsCOMPtr<nsINodeInfo> nodeInfo;
+
   if (!mTextNodeInfo) {
-    mTextNodeInfo = GetNodeInfo(nsGkAtoms::textTagName, nullptr,
-                                kNameSpaceID_None,
-                                nsIDOMNode::TEXT_NODE, nullptr).get();
-  }
-  else {
-    NS_ADDREF(mTextNodeInfo);
+    nodeInfo = GetNodeInfo(nsGkAtoms::textTagName, nullptr, kNameSpaceID_None,
+                           nsIDOMNode::TEXT_NODE, nullptr);
+    // Hold a weak ref; the nodeinfo will let us know when it goes away
+    mTextNodeInfo = nodeInfo;
+  } else {
+    nodeInfo = mTextNodeInfo;
   }
 
-  return mTextNodeInfo;
+  return nodeInfo.forget();
 }
 
 already_AddRefed<nsINodeInfo>
 nsNodeInfoManager::GetCommentNodeInfo()
 {
+  nsCOMPtr<nsINodeInfo> nodeInfo;
+
   if (!mCommentNodeInfo) {
-    mCommentNodeInfo = GetNodeInfo(nsGkAtoms::commentTagName, nullptr,
-                                   kNameSpaceID_None,
-                                   nsIDOMNode::COMMENT_NODE, nullptr).get();
+    nodeInfo = GetNodeInfo(nsGkAtoms::commentTagName, nullptr,
+                           kNameSpaceID_None, nsIDOMNode::COMMENT_NODE,
+                           nullptr);
+    // Hold a weak ref; the nodeinfo will let us know when it goes away
+    mCommentNodeInfo = nodeInfo;
   }
   else {
-    NS_ADDREF(mCommentNodeInfo);
+    nodeInfo = mCommentNodeInfo;
   }
 
-  return mCommentNodeInfo;
+  return nodeInfo.forget();
 }
 
 already_AddRefed<nsINodeInfo>
 nsNodeInfoManager::GetDocumentNodeInfo()
 {
+  nsCOMPtr<nsINodeInfo> nodeInfo;
+
   if (!mDocumentNodeInfo) {
     NS_ASSERTION(mDocument, "Should have mDocument!");
-    mDocumentNodeInfo = GetNodeInfo(nsGkAtoms::documentNodeName, nullptr,
-                                    kNameSpaceID_None,
-                                    nsIDOMNode::DOCUMENT_NODE, nullptr).get();
+    nodeInfo = GetNodeInfo(nsGkAtoms::documentNodeName, nullptr,
+                           kNameSpaceID_None, nsIDOMNode::DOCUMENT_NODE,
+                           nullptr);
+    // Hold a weak ref; the nodeinfo will let us know when it goes away
+    mDocumentNodeInfo = nodeInfo;
+
     --mNonDocumentNodeInfos;
     if (!mNonDocumentNodeInfos) {
       mDocument->Release(); // Don't set mDocument to null!
     }
   }
   else {
-    NS_ADDREF(mDocumentNodeInfo);
+    nodeInfo = mDocumentNodeInfo;
   }
 
-  return mDocumentNodeInfo;
+  return nodeInfo.forget();
 }
 
 void
 nsNodeInfoManager::SetDocumentPrincipal(nsIPrincipal *aPrincipal)
 {
   NS_RELEASE(mPrincipal);
   if (!aPrincipal) {
     aPrincipal = mDefaultPrincipal;