Bug 1207245 - part 2 - move MakeAndAddRef to nsRefPtr.h
authorNathan Froyd <froydnj@mozilla.com>
Tue, 22 Sep 2015 22:23:10 -0400
changeset 299399 86fb8a462b04823fe06d93c8d2f62cd7c32b0da9
parent 299398 a4ee8cbe5e73b70a0bdbb3700703536af55d3529
child 299400 ed0301097c860d6b3ca33156f06e1cb3dde60d03
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1207245
milestone44.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 1207245 - part 2 - move MakeAndAddRef to nsRefPtr.h A number of places depend on RefPtr.h providing this function. When we s/RefPtr/nsRefPtr/, such places still need to be able to see this function. Moving it to nsRefPtr.h makes it still visible before we switch (since RefPtr.h includes nsRefPtr.h), and after we switch (since every place that #includes RefPtr.h will now be #including nsRefPtr.h).
mfbt/RefPtr.h
mfbt/nsRefPtr.h
--- a/mfbt/RefPtr.h
+++ b/mfbt/RefPtr.h
@@ -185,33 +185,16 @@ private:
  */
 template<typename T>
 OutParamRef<T>
 byRef(RefPtr<T>& aPtr)
 {
   return OutParamRef<T>(aPtr);
 }
 
-/**
- * Helper function to be able to conveniently write things like:
- *
- *   already_AddRefed<T>
- *   f(...)
- *   {
- *     return MakeAndAddRef<T>(...);
- *   }
- */
-template<typename T, typename... Args>
-already_AddRefed<T>
-MakeAndAddRef(Args&&... aArgs)
-{
-  RefPtr<T> p(new T(Forward<Args>(aArgs)...));
-  return p.forget();
-}
-
 } // namespace mozilla
 
 // Declared in nsRefPtr.h
 template<class T> template<class U>
 nsRefPtr<T>::nsRefPtr(mozilla::RefPtr<U>&& aOther)
   : nsRefPtr(aOther.forget())
 {
 }
--- a/mfbt/nsRefPtr.h
+++ b/mfbt/nsRefPtr.h
@@ -586,9 +586,30 @@ operator!=(decltype(nullptr), const nsRe
 template <class T>
 inline already_AddRefed<T>
 do_AddRef(T*&& aObj)
 {
   nsRefPtr<T> ref(aObj);
   return ref.forget();
 }
 
+namespace mozilla {
+
+/**
+ * Helper function to be able to conveniently write things like:
+ *
+ *   already_AddRefed<T>
+ *   f(...)
+ *   {
+ *     return MakeAndAddRef<T>(...);
+ *   }
+ */
+template<typename T, typename... Args>
+already_AddRefed<T>
+MakeAndAddRef(Args&&... aArgs)
+{
+  nsRefPtr<T> p(new T(Forward<Args>(aArgs)...));
+  return p.forget();
+}
+
+} // namespace mozilla
+
 #endif /* mozilla_nsRefPtr_h */