Bug 1248784 - Rename the existing AddRefTraits to ConstRemovingRefPtrTraits. r=froydnj
authorBobby Holley <bobbyholley@gmail.com>
Mon, 15 Feb 2016 13:47:33 -0800
changeset 331631 c9431b91f57091c24cbcef01eed66d5fbc76f1ec
parent 331630 cfa9883c56b6e8654afd47d5f6f158bda7cbb096
child 331632 5039eb1fa76cc1872f7c1372b5d8569188d36998
push id11020
push userjolesen@mozilla.com
push dateWed, 17 Feb 2016 18:16:38 +0000
reviewersfroydnj
bugs1248784
milestone47.0a1
Bug 1248784 - Rename the existing AddRefTraits to ConstRemovingRefPtrTraits. r=froydnj
mfbt/RefPtr.h
--- a/mfbt/RefPtr.h
+++ b/mfbt/RefPtr.h
@@ -24,74 +24,74 @@ template<class T> class OwningNonNull;
 template <class T>
 class RefPtr
 {
 private:
   void
   assign_with_AddRef(T* aRawPtr)
   {
     if (aRawPtr) {
-      AddRefTraits<T>::AddRef(aRawPtr);
+      ConstRemovingRefPtrTraits<T>::AddRef(aRawPtr);
     }
     assign_assuming_AddRef(aRawPtr);
   }
 
   void
   assign_assuming_AddRef(T* aNewPtr)
   {
     T* oldPtr = mRawPtr;
     mRawPtr = aNewPtr;
     if (oldPtr) {
-      AddRefTraits<T>::Release(oldPtr);
+      ConstRemovingRefPtrTraits<T>::Release(oldPtr);
     }
   }
 
 private:
   T* MOZ_OWNING_REF mRawPtr;
 
 public:
   typedef T element_type;
 
   ~RefPtr()
   {
     if (mRawPtr) {
-      AddRefTraits<T>::Release(mRawPtr);
+      ConstRemovingRefPtrTraits<T>::Release(mRawPtr);
     }
   }
 
   // Constructors
 
   RefPtr()
     : mRawPtr(0)
     // default constructor
   {
   }
 
   RefPtr(const RefPtr<T>& aSmartPtr)
     : mRawPtr(aSmartPtr.mRawPtr)
     // copy-constructor
   {
     if (mRawPtr) {
-      AddRefTraits<T>::AddRef(mRawPtr);
+      ConstRemovingRefPtrTraits<T>::AddRef(mRawPtr);
     }
   }
 
   RefPtr(RefPtr<T>&& aRefPtr)
     : mRawPtr(aRefPtr.mRawPtr)
   {
     aRefPtr.mRawPtr = nullptr;
   }
 
   // construct from a raw pointer (of the right type)
 
   MOZ_IMPLICIT RefPtr(T* aRawPtr)
     : mRawPtr(aRawPtr)
   {
     if (mRawPtr) {
-      AddRefTraits<T>::AddRef(mRawPtr);
+      ConstRemovingRefPtrTraits<T>::AddRef(mRawPtr);
     }
   }
 
   template <typename I>
   MOZ_IMPLICIT RefPtr(already_AddRefed<I>& aSmartPtr)
     : mRawPtr(aSmartPtr.take())
     // construct from |already_AddRefed|
   {
@@ -105,17 +105,17 @@ public:
   }
 
   template <typename I>
   MOZ_IMPLICIT RefPtr(const RefPtr<I>& aSmartPtr)
     : mRawPtr(aSmartPtr.get())
     // copy-construct from a smart pointer with a related pointer type
   {
     if (mRawPtr) {
-      AddRefTraits<T>::AddRef(mRawPtr);
+      ConstRemovingRefPtrTraits<T>::AddRef(mRawPtr);
     }
   }
 
   template <typename I>
   MOZ_IMPLICIT RefPtr(RefPtr<I>&& aSmartPtr)
     : mRawPtr(aSmartPtr.forget().take())
     // construct from |Move(RefPtr<SomeSubclassOfT>)|.
   {
@@ -331,54 +331,53 @@ public:
 
   T**
   StartAssignment()
   {
     assign_assuming_AddRef(0);
     return reinterpret_cast<T**>(&mRawPtr);
   }
 private:
-  // This helper class makes |RefPtr<const T>| possible by casting away
-  // the constness from the pointer when calling AddRef() and Release().
-  //
-  // This is necessary because AddRef() and Release() implementations can't
-  // generally expected to be const themselves (without heavy use of |mutable|
-  // and |const_cast| in their own implementations).
-  //
-  // This should be sound because while |RefPtr<const T>| provides a
-  // const view of an object, the object itself should not be const (it
-  // would have to be allocated as |new const T| or similar to be const).
-
   // Because some classes make their AddRef/Release implementations private
   // and then friend RefPtr to make them visible, we redirect AddRefTraits's
   // calls to static helper functions in RefPtr so we don't have to figure
   // out how to make AddRefTraits visible to *those* classes.
   static MOZ_ALWAYS_INLINE void
   AddRefTraitsAddRefHelper(typename mozilla::RemoveConst<T>::Type* aPtr)
   {
     aPtr->AddRef();
   }
   static MOZ_ALWAYS_INLINE void
   AddRefTraitsReleaseHelper(typename mozilla::RemoveConst<T>::Type* aPtr)
   {
     aPtr->Release();
   }
 
+  // This helper class makes |RefPtr<const T>| possible by casting away
+  // the constness from the pointer when calling AddRef() and Release().
+  //
+  // This is necessary because AddRef() and Release() implementations can't
+  // generally expected to be const themselves (without heavy use of |mutable|
+  // and |const_cast| in their own implementations).
+  //
+  // This should be sound because while |RefPtr<const T>| provides a
+  // const view of an object, the object itself should not be const (it
+  // would have to be allocated as |new const T| or similar to be const).
   template<class U>
-  struct AddRefTraits
+  struct ConstRemovingRefPtrTraits
   {
     static void AddRef(U* aPtr) {
       RefPtr<T>::AddRefTraitsAddRefHelper(aPtr);
     }
     static void Release(U* aPtr) {
       RefPtr<T>::AddRefTraitsReleaseHelper(aPtr);
     }
   };
   template<class U>
-  struct AddRefTraits<const U>
+  struct ConstRemovingRefPtrTraits<const U>
   {
     static void AddRef(const U* aPtr) {
       RefPtr<T>::AddRefTraitsAddRefHelper(const_cast<U*>(aPtr));
     }
     static void Release(const U* aPtr) {
       RefPtr<T>::AddRefTraitsReleaseHelper(const_cast<U*>(aPtr));
     }
   };