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 224514 b9c534b922c710bfb06c0e16cd673095e3310ef9
parent 224513 aafe9d60279fda8bf84db29f5fde19aa2cea49fc
child 224515 a3fe6eeb1f1f20539499e65b2d323645027f4c6e
push id28134
push userphilringnalda@gmail.com
push dateTue, 20 Jan 2015 02:25:52 +0000
treeherdermozilla-central@bd9efbbfa8e6 [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)