Bug 1281626 - part 4 - change NS_NewRunnableFunction to return already_AddRefed; r=khuey
authorNathan Froyd <froydnj@gmail.com>
Tue, 28 Jun 2016 22:24:54 -0400
changeset 382171 62b499433ebd956e08af947a6798c4dcc61aa4a7
parent 382170 aba3ae25c8ffda82ed8cf75846b93d51de27ec14
child 382172 c5cba49844eed069e50a54045d1c284643f34165
push id21645
push userbmo:gasolin@mozilla.com
push dateWed, 29 Jun 2016 04:02:20 +0000
reviewerskhuey
bugs1281626
milestone50.0a1
Bug 1281626 - part 4 - change NS_NewRunnableFunction to return already_AddRefed; r=khuey This change makes it more consistent with NS_NewRunnableMethod and also opens up optimization opportunities for later.
xpcom/glue/nsThreadUtils.h
--- a/xpcom/glue/nsThreadUtils.h
+++ b/xpcom/glue/nsThreadUtils.h
@@ -278,24 +278,24 @@ public:
     mFunction();
     return NS_OK;
   }
 private:
   StoredFunction mFunction;
 };
 
 template<typename Function>
-nsRunnableFunction<typename mozilla::RemoveReference<Function>::Type>*
+already_AddRefed<nsRunnableFunction<typename mozilla::RemoveReference<Function>::Type>>
 NS_NewRunnableFunction(Function&& aFunction)
 {
-  return new nsRunnableFunction
-               // Make sure we store a non-reference in nsRunnableFunction.
-               <typename mozilla::RemoveReference<Function>::Type>
-               // But still forward aFunction to move if possible.
-               (mozilla::Forward<Function>(aFunction));
+  return do_AddRef(new nsRunnableFunction
+                   // Make sure we store a non-reference in nsRunnableFunction.
+                   <typename mozilla::RemoveReference<Function>::Type>
+                   // But still forward aFunction to move if possible.
+                   (mozilla::Forward<Function>(aFunction)));
 }
 
 // An event that can be used to call a method on a class.  The class type must
 // support reference counting. This event supports Revoke for use
 // with nsRevocableEventPtr.
 template<class ClassType,
          typename ReturnType = void,
          bool Owning = true,