Bug 1121489 - Make it possible to construct a RefPtr from an already_AddRefed; r=froydnj
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 14 Jan 2015 10:09:28 -0500
changeset 224492 b9c534b922c710bfb06c0e16cd673095e3310ef9
parent 224491 aafe9d60279fda8bf84db29f5fde19aa2cea49fc
child 224493 a3fe6eeb1f1f20539499e65b2d323645027f4c6e
push id54251
push usereakhgari@mozilla.com
push dateMon, 19 Jan 2015 14:01:04 +0000
treeherdermozilla-inbound@a3fe6eeb1f1f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1121489
milestone38.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 1121489 - Make it possible to construct a RefPtr from an already_AddRefed; r=froydnj This will pave the way towards having a MakeAndAddRef function that returns an already_AddRefed and can be used in graphics code.
mfbt/RefPtr.h
--- a/mfbt/RefPtr.h
+++ b/mfbt/RefPtr.h
@@ -4,16 +4,17 @@
  * 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/. */
 
 /* Helpers for defining and using refcounted objects. */
 
 #ifndef mozilla_RefPtr_h
 #define mozilla_RefPtr_h
 
+#include "mozilla/AlreadyAddRefed.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/RefCountType.h"
 #include "mozilla/TypeTraits.h"
 #if defined(MOZILLA_INTERNAL_API)
 #include "nsXPCOM.h"
 #endif
@@ -230,16 +231,17 @@ class RefPtr
   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(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)
@@ -247,16 +249,21 @@ public:
     assign(ref(aOther.mPtr));
     return *this;
   }
   RefPtr& operator=(const TemporaryRef<T>& aOther)
   {
     assign(aOther.take());
     return *this;
   }
+  RefPtr& operator=(const already_AddRefed<T>& aOther)
+  {
+    assign(aOther.take());
+    return *this;
+  }
   RefPtr& operator=(T* aVal)
   {
     assign(ref(aVal));
     return *this;
   }
 
   template<typename U>
   RefPtr& operator=(const RefPtr<U>& aOther)