Bug 1188696 - Remove the XPCOM dependencies in nsRefPtr.h. r=froydnj
authorBobby Holley <bobbyholley@gmail.com>
Tue, 28 Jul 2015 17:45:58 -0700
changeset 286903 dd6950f8f2baa1446846c48bdb0d700a38f7852a
parent 286902 63ad8e412a0f3fb679ddec0183c1ee0bb981b748
child 286904 81beff07c6dc8176f2d78d443a716259fe6be924
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1188696
milestone42.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 1188696 - Remove the XPCOM dependencies in nsRefPtr.h. r=froydnj
xpcom/base/nsRefPtr.h
xpcom/glue/nsCOMPtr.h
xpcom/glue/nsISupportsUtils.h
--- a/xpcom/base/nsRefPtr.h
+++ b/xpcom/base/nsRefPtr.h
@@ -3,19 +3,18 @@
 /* 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 nsRefPtr_h
 #define nsRefPtr_h
 
 #include "mozilla/AlreadyAddRefed.h"
+#include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
-#include "nsDebug.h"
-#include "nsISupportsUtils.h"
 
 /*****************************************************************************/
 
 // template <class T> class nsRefPtrGetterAddRefs;
 
 class nsCOMPtr_helper;
 
 namespace mozilla {
@@ -211,17 +210,17 @@ public:
   template <typename I>
   void
   forget(I** aRhs)
   // Set the target of aRhs to the value of mRawPtr and null out mRawPtr.
   // Useful to avoid unnecessary AddRef/Release pairs with "out"
   // parameters where aRhs bay be a T** or an I** where I is a base class
   // of T.
   {
-    NS_ASSERTION(aRhs, "Null pointer passed to forget!");
+    MOZ_ASSERT(aRhs, "Null pointer passed to forget!");
     *aRhs = mRawPtr;
     mRawPtr = 0;
   }
 
   T*
   get() const
   /*
     Prefer the implicit conversion provided automatically by |operator T*() const|.
@@ -242,31 +241,31 @@ public:
   */
   {
     return get();
   }
 
   T*
   operator->() const MOZ_NO_ADDREF_RELEASE_ON_RETURN
   {
-    NS_PRECONDITION(mRawPtr != 0,
-                    "You can't dereference a NULL nsRefPtr with operator->().");
+    MOZ_ASSERT(mRawPtr != 0,
+               "You can't dereference a NULL nsRefPtr with operator->().");
     return get();
   }
 
   // This operator is needed for gcc <= 4.0.* and for Sun Studio; it
   // causes internal compiler errors for some MSVC versions.  (It's not
   // clear to me whether it should be needed.)
 #ifndef _MSC_VER
   template <class U, class V>
   U&
   operator->*(U V::* aMember)
   {
-    NS_PRECONDITION(mRawPtr != 0,
-                    "You can't dereference a NULL nsRefPtr with operator->*().");
+    MOZ_ASSERT(mRawPtr != 0,
+               "You can't dereference a NULL nsRefPtr with operator->*().");
     return get()->*aMember;
   }
 #endif
 
   nsRefPtr<T>*
   get_address()
   // This is not intended to be used by clients.  See |address_of|
   // below.
@@ -281,51 +280,29 @@ public:
   {
     return this;
   }
 
 public:
   T&
   operator*() const
   {
-    NS_PRECONDITION(mRawPtr != 0,
-                    "You can't dereference a NULL nsRefPtr with operator*().");
+    MOZ_ASSERT(mRawPtr != 0,
+               "You can't dereference a NULL nsRefPtr with operator*().");
     return *get();
   }
 
   T**
   StartAssignment()
   {
     assign_assuming_AddRef(0);
     return reinterpret_cast<T**>(&mRawPtr);
   }
 };
 
-template <class T>
-nsRefPtr<T>::nsRefPtr(const nsCOMPtr_helper& aHelper)
-{
-  void* newRawPtr;
-  if (NS_FAILED(aHelper(NS_GET_TEMPLATE_IID(T), &newRawPtr))) {
-    newRawPtr = 0;
-  }
-  mRawPtr = static_cast<T*>(newRawPtr);
-}
-
-template <class T>
-nsRefPtr<T>&
-nsRefPtr<T>::operator=(const nsCOMPtr_helper& aHelper)
-{
-  void* newRawPtr;
-  if (NS_FAILED(aHelper(NS_GET_TEMPLATE_IID(T), &newRawPtr))) {
-    newRawPtr = 0;
-  }
-  assign_assuming_AddRef(static_cast<T*>(newRawPtr));
-  return *this;
-}
-
 class nsCycleCollectionTraversalCallback;
 template <typename T>
 void
 CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback,
                          T* aChild, const char* aName, uint32_t aFlags);
 
 template <typename T>
 inline void
@@ -527,24 +504,16 @@ operator!=(const nsRefPtr<T>& aLhs, ::de
 template <class T>
 inline bool
 operator!=(::detail::nsRefPtrZero* aLhs, const nsRefPtr<T>& aRhs)
 // specifically to allow |0 != smartPtr|
 {
   return reinterpret_cast<const void*>(aLhs) != static_cast<const void*>(aRhs.get());
 }
 
-
-template <class SourceType, class DestinationType>
-inline nsresult
-CallQueryInterface(nsRefPtr<SourceType>& aSourcePtr, DestinationType** aDestPtr)
-{
-  return CallQueryInterface(aSourcePtr.get(), aDestPtr);
-}
-
 /*****************************************************************************/
 
 template <class T>
 inline already_AddRefed<T>
 do_AddRef(T*&& aObj)
 {
   nsRefPtr<T> ref(aObj);
   return ref.forget();
--- a/xpcom/glue/nsCOMPtr.h
+++ b/xpcom/glue/nsCOMPtr.h
@@ -23,16 +23,17 @@
 #include "mozilla/AlreadyAddRefed.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Move.h"
 #include "mozilla/TypeTraits.h"
 
 #include "nsDebug.h" // for |NS_ASSERTION|
 #include "nsISupportsUtils.h" // for |nsresult|, |NS_ADDREF|, |NS_GET_TEMPLATE_IID| et al
+#include "nsRefPtr.h"
 
 #include "nsCycleCollectionNoteChild.h"
 
 
 /*
  * WARNING: This file defines several macros for internal use only. These
  * macros begin with the prefix |NSCAP_|. Do not use these macros in your own
  * code. They are for internal use only for cross-platform compatibility, and
@@ -1372,9 +1373,32 @@ SameCOMIdentity(nsISupports* aLhs, nsISu
 
 template<class SourceType, class DestinationType>
 inline nsresult
 CallQueryInterface(nsCOMPtr<SourceType>& aSourcePtr, DestinationType** aDestPtr)
 {
   return CallQueryInterface(aSourcePtr.get(), aDestPtr);
 }
 
+template <class T>
+nsRefPtr<T>::nsRefPtr(const nsCOMPtr_helper& aHelper)
+{
+  void* newRawPtr;
+  if (NS_FAILED(aHelper(NS_GET_TEMPLATE_IID(T), &newRawPtr))) {
+    newRawPtr = 0;
+  }
+  mRawPtr = static_cast<T*>(newRawPtr);
+}
+
+template <class T>
+nsRefPtr<T>&
+nsRefPtr<T>::operator=(const nsCOMPtr_helper& aHelper)
+{
+  void* newRawPtr;
+  if (NS_FAILED(aHelper(NS_GET_TEMPLATE_IID(T), &newRawPtr))) {
+    newRawPtr = 0;
+  }
+  assign_assuming_AddRef(static_cast<T*>(newRawPtr));
+  return *this;
+}
+
+
 #endif // !defined(nsCOMPtr_h___)
--- a/xpcom/glue/nsISupportsUtils.h
+++ b/xpcom/glue/nsISupportsUtils.h
@@ -7,16 +7,17 @@
 #ifndef nsISupportsUtils_h__
 #define nsISupportsUtils_h__
 
 #include "nscore.h"
 #include "nsISupportsBase.h"
 #include "nsError.h"
 #include "nsDebug.h"
 #include "nsISupportsImpl.h"
+#include "nsRefPtr.h"
 #include "mozilla/TypeTraits.h"
 
 /**
  * Macro for adding a reference to an interface.
  * @param _ptr The interface pointer.
  */
 #define NS_ADDREF(_ptr) \
   (_ptr)->AddRef()
@@ -129,9 +130,16 @@ CallQueryInterface(T* aSource, Destinati
 
   NS_PRECONDITION(aSource, "null parameter");
   NS_PRECONDITION(aDestination, "null parameter");
 
   return aSource->QueryInterface(NS_GET_TEMPLATE_IID(DestinationType),
                                  reinterpret_cast<void**>(aDestination));
 }
 
+template <class SourceType, class DestinationType>
+inline nsresult
+CallQueryInterface(nsRefPtr<SourceType>& aSourcePtr, DestinationType** aDestPtr)
+{
+  return CallQueryInterface(aSourcePtr.get(), aDestPtr);
+}
+
 #endif /* __nsISupportsUtils_h */