Bug 1368382. P1 - rename and make MethodThenValue/FunctionValue specializations of ThenValue<>. r=gerald
authorJW Wang <jwwang@mozilla.com>
Wed, 31 May 2017 07:44:53 +0800
changeset 361727 f143a22591fa3f095c2b01c63937417f46826eff
parent 361726 843cd9454b8e37200471827f192e3a406c126b69
child 361728 a6df0f5e3000f7992c9cf4e0161887a8f465a906
push id31939
push usercbook@mozilla.com
push dateThu, 01 Jun 2017 11:49:28 +0000
treeherdermozilla-central@d96110d76619 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1368382
milestone55.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 1368382. P1 - rename and make MethodThenValue/FunctionValue specializations of ThenValue<>. r=gerald This allows us to remove 2 overloads of MozPromise::Then() using variadic template. MozReview-Commit-ID: 5LHwDhIhh8e
xpcom/threads/MozPromise.h
--- a/xpcom/threads/MozPromise.h
+++ b/xpcom/threads/MozPromise.h
@@ -538,27 +538,37 @@ protected:
                            !TakesArgument<MethodType>::value,
                            already_AddRefed<MozPromise>>::Type
   InvokeCallbackMethod(ThisType* aThisVal, MethodType aMethod, ValueType&& aValue)
   {
     ((*aThisVal).*aMethod)();
     return nullptr;
   }
 
-  template<typename ThisType, typename ResolveMethodType, typename RejectMethodType>
-  class MethodThenValue : public ThenValueBase
+  template<typename...>
+  class ThenValue;
+
+  template<typename ThisType,
+           typename ResolveMethodType,
+           typename RejectMethodType>
+  class ThenValue<ThisType*, ResolveMethodType, RejectMethodType>
+    : public ThenValueBase
   {
   public:
-    MethodThenValue(AbstractThread* aResponseTarget, ThisType* aThisVal,
-                    ResolveMethodType aResolveMethod, RejectMethodType aRejectMethod,
-                    const char* aCallSite)
+    ThenValue(AbstractThread* aResponseTarget,
+              ThisType* aThisVal,
+              ResolveMethodType aResolveMethod,
+              RejectMethodType aRejectMethod,
+              const char* aCallSite)
       : ThenValueBase(aResponseTarget, aCallSite)
       , mThisVal(aThisVal)
       , mResolveMethod(aResolveMethod)
-      , mRejectMethod(aRejectMethod) {}
+      , mRejectMethod(aRejectMethod)
+    {
+    }
 
     void Disconnect() override
     {
       ThenValueBase::Disconnect();
 
       // If a Request has been disconnected, we don't guarantee that the
       // resolve/reject runnable will be dispatched. Null out our refcounted
       // this-value now so that it's released predictably on the dispatch thread.
@@ -587,25 +597,24 @@ protected:
     }
 
   private:
     RefPtr<ThisType> mThisVal; // Only accessed and refcounted on dispatch thread.
     ResolveMethodType mResolveMethod;
     RejectMethodType mRejectMethod;
   };
 
-  // Specialization of MethodThenValue (with 3rd template arg being 'void')
-  // that only takes one method, to be called with a ResolveOrRejectValue.
   template<typename ThisType, typename ResolveRejectMethodType>
-  class MethodThenValue<ThisType, ResolveRejectMethodType, void> : public ThenValueBase
+  class ThenValue<ThisType*, ResolveRejectMethodType> : public ThenValueBase
   {
   public:
-    MethodThenValue(AbstractThread* aResponseTarget, ThisType* aThisVal,
-                    ResolveRejectMethodType aResolveRejectMethod,
-                    const char* aCallSite)
+    ThenValue(AbstractThread* aResponseTarget,
+              ThisType* aThisVal,
+              ResolveRejectMethodType aResolveRejectMethod,
+              const char* aCallSite)
       : ThenValueBase(aResponseTarget, aCallSite)
       , mThisVal(aThisVal)
       , mResolveRejectMethod(aResolveRejectMethod)
     {}
 
     void Disconnect() override
     {
       ThenValueBase::Disconnect();
@@ -633,23 +642,23 @@ protected:
 
   private:
     RefPtr<ThisType> mThisVal; // Only accessed and refcounted on dispatch thread.
     ResolveRejectMethodType mResolveRejectMethod;
   };
 
   // NB: We could use std::function here instead of a template if it were supported. :-(
   template<typename ResolveFunction, typename RejectFunction>
-  class FunctionThenValue : public ThenValueBase
+  class ThenValue<ResolveFunction, RejectFunction> : public ThenValueBase
   {
   public:
-    FunctionThenValue(AbstractThread* aResponseTarget,
-                      ResolveFunction&& aResolveFunction,
-                      RejectFunction&& aRejectFunction,
-                      const char* aCallSite)
+    ThenValue(AbstractThread* aResponseTarget,
+              ResolveFunction&& aResolveFunction,
+              RejectFunction&& aRejectFunction,
+              const char* aCallSite)
       : ThenValueBase(aResponseTarget, aCallSite)
     {
       mResolveFunction.emplace(Move(aResolveFunction));
       mRejectFunction.emplace(Move(aRejectFunction));
     }
 
     void Disconnect() override
     {
@@ -690,25 +699,23 @@ protected:
       return completion.forget();
     }
 
   private:
     Maybe<ResolveFunction> mResolveFunction; // Only accessed and deleted on dispatch thread.
     Maybe<RejectFunction> mRejectFunction; // Only accessed and deleted on dispatch thread.
   };
 
-  // Specialization of FunctionThenValue (with 2nd template arg being 'void')
-  // that only takes one function, to be called with a ResolveOrRejectValue.
   template<typename ResolveRejectFunction>
-  class FunctionThenValue<ResolveRejectFunction, void> : public ThenValueBase
+  class ThenValue<ResolveRejectFunction> : public ThenValueBase
   {
   public:
-    FunctionThenValue(AbstractThread* aResponseTarget,
-                      ResolveRejectFunction&& aResolveRejectFunction,
-                      const char* aCallSite)
+    ThenValue(AbstractThread* aResponseTarget,
+              ResolveRejectFunction&& aResolveRejectFunction,
+              const char* aCallSite)
       : ThenValueBase(aResponseTarget, aCallSite)
     {
       mResolveRejectFunction.emplace(Move(aResolveRejectFunction));
     }
 
     void Disconnect() override
     {
       ThenValueBase::Disconnect();
@@ -890,53 +897,53 @@ private:
   };
 
 public:
   template<typename ThisType, typename ResolveMethodType, typename RejectMethodType>
   typename MethodThenCommand<ResolveMethodType, RejectMethodType>::type
   Then(AbstractThread* aResponseThread, const char* aCallSite,
     ThisType* aThisVal, ResolveMethodType aResolveMethod, RejectMethodType aRejectMethod)
   {
-    using ThenType = MethodThenValue<ThisType, ResolveMethodType, RejectMethodType>;
+    using ThenType = ThenValue<ThisType*, ResolveMethodType, RejectMethodType>;
     RefPtr<ThenValueBase> thenValue = new ThenType(aResponseThread,
        aThisVal, aResolveMethod, aRejectMethod, aCallSite);
     return typename MethodThenCommand<ResolveMethodType, RejectMethodType>::type(
       aResponseThread, aCallSite, thenValue.forget(), this);
   }
 
   template<typename ThisType, typename ResolveRejectMethodType>
   typename MethodThenCommand<ResolveRejectMethodType>::type
   Then(AbstractThread* aResponseThread, const char* aCallSite,
     ThisType* aThisVal, ResolveRejectMethodType aResolveRejectMethod)
   {
-    using ThenType = MethodThenValue<ThisType, ResolveRejectMethodType, void>;
+    using ThenType = ThenValue<ThisType*, ResolveRejectMethodType>;
     RefPtr<ThenValueBase> thenValue = new ThenType(aResponseThread,
        aThisVal, aResolveRejectMethod, aCallSite);
     return typename MethodThenCommand<ResolveRejectMethodType>::type(
       aResponseThread, aCallSite, thenValue.forget(), this);
   }
 
   template<typename ResolveFunction, typename RejectFunction>
   typename FunctionThenCommand<ResolveFunction, RejectFunction>::type
   Then(AbstractThread* aResponseThread, const char* aCallSite,
     ResolveFunction&& aResolveFunction, RejectFunction&& aRejectFunction)
   {
-    using ThenType = FunctionThenValue<ResolveFunction, RejectFunction>;
+    using ThenType = ThenValue<ResolveFunction, RejectFunction>;
     RefPtr<ThenValueBase> thenValue = new ThenType(aResponseThread,
       Move(aResolveFunction), Move(aRejectFunction), aCallSite);
     return typename FunctionThenCommand<ResolveFunction, RejectFunction>::type(
       aResponseThread, aCallSite, thenValue.forget(), this);
   }
 
   template<typename ResolveRejectFunction>
   typename FunctionThenCommand<ResolveRejectFunction>::type
   Then(AbstractThread* aResponseThread, const char* aCallSite,
                    ResolveRejectFunction&& aResolveRejectFunction)
   {
-    using ThenType = FunctionThenValue<ResolveRejectFunction, void>;
+    using ThenType = ThenValue<ResolveRejectFunction>;
     RefPtr<ThenValueBase> thenValue = new ThenType(aResponseThread,
       Move(aResolveRejectFunction), aCallSite);
     return typename FunctionThenCommand<ResolveRejectFunction>::type(
       aResponseThread, aCallSite, thenValue.forget(), this);
   }
 
   void ChainTo(already_AddRefed<Private> aChainedPromise, const char* aCallSite)
   {