Bug 1044658 - 2/6 - remove useless base classes around WeakPtr - r=froydnj
authorBenoit Jacob <bjacob@mozilla.com>
Wed, 30 Jul 2014 15:52:02 -0400
changeset 196938 a8f57c397a0449f565b61b3791a071304292b012
parent 196937 cd926197c6c91d7222e177a6e6e6c2950c862bb3
child 196939 77a2a058bc912c083750a9dd85cf1792e6141ff9
push id27228
push usercbook@mozilla.com
push dateThu, 31 Jul 2014 10:58:52 +0000
treeherdermozilla-central@aa176fcc56b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1044658
milestone34.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 1044658 - 2/6 - remove useless base classes around WeakPtr - r=froydnj
mfbt/WeakPtr.h
--- a/mfbt/WeakPtr.h
+++ b/mfbt/WeakPtr.h
@@ -72,23 +72,23 @@
 #include "mozilla/NullPtr.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/TypeTraits.h"
 
 #include <string.h>
 
 namespace mozilla {
 
-template <typename T> class WeakPtrBase;
-template <typename T> class SupportsWeakPtrBase;
+template <typename T> class WeakPtr;
+template <typename T> class SupportsWeakPtr;
 
 namespace detail {
 
 // This can live beyond the lifetime of the class derived from
-// SupportsWeakPtrBase.
+// SupportsWeakPtr.
 template<class T>
 class WeakReference : public ::mozilla::RefCounted<WeakReference<T> >
 {
 public:
   explicit WeakReference(T* p) : mPtr(p) {}
 
   T* get() const { return mPtr; }
 
@@ -113,90 +113,75 @@ public:
     return nameBuffer;
   }
 
   size_t typeSize() const { return sizeof(*this); }
 #undef snprintf
 #endif
 
 private:
-  friend class WeakPtrBase<T>;
-  friend class SupportsWeakPtrBase<T>;
+  friend class WeakPtr<T>;
+  friend class SupportsWeakPtr<T>;
 
   void detach() { mPtr = nullptr; }
 
   T* mPtr;
 };
 
 } // namespace detail
 
 template <typename T>
-class SupportsWeakPtrBase
+class SupportsWeakPtr
 {
 public:
-  WeakPtrBase<T> asWeakPtr()
+  WeakPtr<T> asWeakPtr()
   {
     if (!weakRef) {
       weakRef = new detail::WeakReference<T>(static_cast<T*>(this));
     }
-    return WeakPtrBase<T>(weakRef);
+    return WeakPtr<T>(weakRef);
   }
 
 protected:
-  ~SupportsWeakPtrBase()
+  ~SupportsWeakPtr()
   {
-    static_assert(IsBaseOf<SupportsWeakPtrBase<T>, T>::value,
-                  "T must derive from SupportsWeakPtrBase<T>");
+    static_assert(IsBaseOf<SupportsWeakPtr<T>, T>::value,
+                  "T must derive from SupportsWeakPtr<T>");
     if (weakRef) {
       weakRef->detach();
     }
   }
 
 private:
-  friend class WeakPtrBase<T>;
+  friend class WeakPtr<T>;
 
   RefPtr<detail::WeakReference<T>> weakRef;
 };
 
 template <typename T>
-class SupportsWeakPtr : public SupportsWeakPtrBase<T>
-{
-};
-
-template <typename T>
-class WeakPtrBase
+class WeakPtr
 {
 public:
-  WeakPtrBase(const WeakPtrBase<T>& aOther)
+  WeakPtr(const WeakPtr<T>& aOther)
     : mRef(aOther.mRef)
   {}
 
   // Ensure that mRef is dereferenceable in the uninitialized state.
-  WeakPtrBase() : mRef(new detail::WeakReference<T>(nullptr)) {}
+  WeakPtr() : mRef(new detail::WeakReference<T>(nullptr)) {}
 
   operator T*() const { return mRef->get(); }
   T& operator*() const { return *mRef->get(); }
 
   T* operator->() const { return mRef->get(); }
 
   T* get() const { return mRef->get(); }
 
 private:
-  friend class SupportsWeakPtrBase<T>;
+  friend class SupportsWeakPtr<T>;
 
-  explicit WeakPtrBase(const RefPtr<detail::WeakReference<T>>& aOther) : mRef(aOther) {}
+  explicit WeakPtr(const RefPtr<detail::WeakReference<T>>& aOther) : mRef(aOther) {}
 
   RefPtr<detail::WeakReference<T>> mRef;
 };
 
-template <typename T>
-class WeakPtr : public WeakPtrBase<T>
-{
-  typedef WeakPtrBase<T> Base;
-public:
-  WeakPtr(const WeakPtr<T>& aOther) : Base(aOther) {}
-  MOZ_IMPLICIT WeakPtr(const Base& aOther) : Base(aOther) {}
-  WeakPtr() {}
-};
-
 } // namespace mozilla
 
 #endif /* mozilla_WeakPtr_h */