Bug 1161627 - part 3 - remove TemporaryRef<T> from RefPtr.h; r=ehsan
authorNathan Froyd <froydnj@mozilla.com>
Tue, 05 May 2015 13:22:12 -0400
changeset 284066 d418eb96a90d8dcf718683f5efb4965f4dc4e820
parent 284065 c664375c0d5bed41821b4a9eaa298e3856efe1d2
child 284067 d16f54dfcc55791c2a8cdfefb6344066ea2a5bf3
push id934
push userraliiev@mozilla.com
push dateMon, 26 Oct 2015 12:58:05 +0000
treeherdermozilla-release@05704e35c1d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1161627
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 1161627 - part 3 - remove TemporaryRef<T> from RefPtr.h; r=ehsan
mfbt/RefPtr.h
--- a/mfbt/RefPtr.h
+++ b/mfbt/RefPtr.h
@@ -25,17 +25,16 @@
     (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING))
 #define MOZ_REFCOUNTED_LEAK_CHECKING
 #endif
 
 namespace mozilla {
 
 template<typename T> class RefCounted;
 template<typename T> class RefPtr;
-template<typename T> class TemporaryRef;
 template<typename T> class OutParamRef;
 template<typename T> OutParamRef<T> byRef(RefPtr<T>&);
 
 /**
  * RefCounted<T> is a sort of a "mixin" for a class T.  RefCounted
  * manages, well, refcounting for T, and because RefCounted is
  * parameterized on T, RefCounted<T> can call T's destructor directly.
  * This means T doesn't need to have a virtual dtor and so doesn't
@@ -222,44 +221,37 @@ public:
  * A RefPtr can forget its underlying T*, which results in the T*
  * being wrapped in a temporary object until the T* is either
  * re-adopted from or released by the temporary.
  */
 template<typename T>
 class RefPtr
 {
   // To allow them to use unref()
-  friend class TemporaryRef<T>;
   friend class OutParamRef<T>;
 
   struct DontRef {};
 
 public:
   RefPtr() : mPtr(0) {}
   RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.mPtr)) {}
-  MOZ_IMPLICIT RefPtr(const TemporaryRef<T>& aOther) : mPtr(aOther.take()) {}
   MOZ_IMPLICIT RefPtr(already_AddRefed<T>& aOther) : mPtr(aOther.take()) {}
   MOZ_IMPLICIT RefPtr(already_AddRefed<T>&& aOther) : mPtr(aOther.take()) {}
   MOZ_IMPLICIT RefPtr(T* aVal) : mPtr(ref(aVal)) {}
 
   template<typename U>
   RefPtr(const RefPtr<U>& aOther) : mPtr(ref(aOther.get())) {}
 
   ~RefPtr() { unref(mPtr); }
 
   RefPtr& operator=(const RefPtr& aOther)
   {
     assign(ref(aOther.mPtr));
     return *this;
   }
-  RefPtr& operator=(const TemporaryRef<T>& aOther)
-  {
-    assign(aOther.take());
-    return *this;
-  }
   RefPtr& operator=(already_AddRefed<T>& aOther)
   {
     assign(aOther.take());
     return *this;
   }
   RefPtr& operator=(already_AddRefed<T>&& aOther)
   {
     assign(aOther.take());
@@ -311,70 +303,26 @@ private:
   {
     if (aVal) {
       aVal->Release();
     }
   }
 };
 
 /**
- * TemporaryRef<T> represents an object that holds a temporary
- * reference to a T.  TemporaryRef objects can't be manually ref'd or
- * unref'd (being temporaries, not lvalues), so can only relinquish
- * references to other objects, or unref on destruction.
- */
-template<typename T>
-class TemporaryRef
-{
-  // To allow it to construct TemporaryRef from a bare T*
-  friend class RefPtr<T>;
-
-  typedef typename RefPtr<T>::DontRef DontRef;
-
-public:
-  // Please see already_AddRefed for a description of what these constructors
-  // do.
-  TemporaryRef() : mPtr(nullptr) {}
-  typedef void (TemporaryRef::* MatchNullptr)(double, float);
-  MOZ_IMPLICIT TemporaryRef(MatchNullptr aRawPtr) : mPtr(nullptr) {}
-  explicit TemporaryRef(T* aVal) : mPtr(RefPtr<T>::ref(aVal)) {}
-
-  TemporaryRef(const TemporaryRef& aOther) : mPtr(aOther.take()) {}
-
-  template<typename U>
-  TemporaryRef(const TemporaryRef<U>& aOther) : mPtr(aOther.take()) {}
-
-  ~TemporaryRef() { RefPtr<T>::unref(mPtr); }
-
-  MOZ_WARN_UNUSED_RESULT T* take() const
-  {
-    T* tmp = mPtr;
-    mPtr = nullptr;
-    return tmp;
-  }
-
-private:
-  TemporaryRef(T* aVal, const DontRef&) : mPtr(aVal) {}
-
-  mutable T* MOZ_OWNING_REF mPtr;
-
-  void operator=(const TemporaryRef&) = delete;
-};
-
-/**
  * OutParamRef is a wrapper that tracks a refcounted pointer passed as
  * an outparam argument to a function.  OutParamRef implements COM T**
  * outparam semantics: this requires the callee to AddRef() the T*
  * returned through the T** outparam on behalf of the caller.  This
  * means the caller (through OutParamRef) must Release() the old
  * object contained in the tracked RefPtr.  It's OK if the callee
  * returns the same T* passed to it through the T** outparam, as long
  * as the callee obeys the COM discipline.
  *
- * Prefer returning TemporaryRef<T> from functions over creating T**
+ * Prefer returning already_AddRefed<T> from functions over creating T**
  * outparams and passing OutParamRef<T> to T**.  Prefer RefPtr<T>*
  * outparams over T** outparams.
  */
 template<typename T>
 class OutParamRef
 {
   friend OutParamRef byRef<T>(RefPtr<T>&);