Bug 1504531 - P1. Use forward references in MozPromiseHolder. r=gerald
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 05 Nov 2018 14:26:23 +0000
changeset 444444 d52d219bbf6baae4a868316e3edc6c83be32f83b
parent 444443 e3a9e32b069a38af83b0f3b2a311dd5b3ce4d0d1
child 444445 9bc3707f8ae4b19d4f63f689924893608fa7f75c
push id109593
push usernbeleuzu@mozilla.com
push dateMon, 05 Nov 2018 21:54:22 +0000
treeherdermozilla-inbound@c58b8835f297 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1504531
milestone65.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 1504531 - P1. Use forward references in MozPromiseHolder. r=gerald Differential Revision: https://phabricator.services.mozilla.com/D10833
dom/media/gmp/ChromiumCDMParent.cpp
xpcom/threads/MozPromise.h
--- a/dom/media/gmp/ChromiumCDMParent.cpp
+++ b/dom/media/gmp/ChromiumCDMParent.cpp
@@ -815,17 +815,18 @@ ChromiumCDMParent::RecvDecodedShmem(cons
 
   return IPC_OK();
 }
 
 void
 ChromiumCDMParent::ReorderAndReturnOutput(RefPtr<VideoData>&& aFrame)
 {
   if (mMaxRefFrames == 0) {
-    mDecodePromise.ResolveIfExists({ std::move(aFrame) }, __func__);
+    mDecodePromise.ResolveIfExists(
+      MediaDataDecoder::DecodedData({ std::move(aFrame) }), __func__);
     return;
   }
   mReorderQueue.Push(std::move(aFrame));
   MediaDataDecoder::DecodedData results;
   while (mReorderQueue.Length() > mMaxRefFrames) {
     results.AppendElement(mReorderQueue.Pop());
   }
   mDecodePromise.Resolve(std::move(results), __func__);
--- a/xpcom/threads/MozPromise.h
+++ b/xpcom/threads/MozPromise.h
@@ -1211,85 +1211,53 @@ public:
   already_AddRefed<typename PromiseType::Private> Steal()
   {
     if (mMonitor) {
       mMonitor->AssertCurrentThreadOwns();
     }
     return mPromise.forget();
   }
 
-  void Resolve(const typename PromiseType::ResolveValueType& aResolveValue,
-               const char* aMethodName)
-  {
-    if (mMonitor) {
-      mMonitor->AssertCurrentThreadOwns();
-    }
-    MOZ_ASSERT(mPromise);
-    mPromise->Resolve(aResolveValue, aMethodName);
-    mPromise = nullptr;
-  }
-  void Resolve(typename PromiseType::ResolveValueType&& aResolveValue,
-               const char* aMethodName)
+  template<typename ResolveValueType_>
+  void Resolve(ResolveValueType_&& aResolveValue, const char* aMethodName)
   {
     if (mMonitor) {
       mMonitor->AssertCurrentThreadOwns();
     }
     MOZ_ASSERT(mPromise);
-    mPromise->Resolve(std::move(aResolveValue), aMethodName);
+    mPromise->Resolve(std::forward<ResolveValueType_>(aResolveValue),
+                      aMethodName);
     mPromise = nullptr;
   }
 
-  void ResolveIfExists(const typename PromiseType::ResolveValueType& aResolveValue,
+  template<typename ResolveValueType_>
+  void ResolveIfExists(ResolveValueType_&& aResolveValue,
                        const char* aMethodName)
   {
     if (!IsEmpty()) {
-      Resolve(aResolveValue, aMethodName);
-    }
-  }
-  void ResolveIfExists(typename PromiseType::ResolveValueType&& aResolveValue,
-                       const char* aMethodName)
-  {
-    if (!IsEmpty()) {
-      Resolve(std::move(aResolveValue), aMethodName);
+      Resolve(std::forward<ResolveValueType_>(aResolveValue), aMethodName);
     }
   }
 
-  void Reject(const typename PromiseType::RejectValueType& aRejectValue,
-              const char* aMethodName)
+  template<typename RejectValueType_>
+  void Reject(RejectValueType_&& aRejectValue, const char* aMethodName)
   {
     if (mMonitor) {
       mMonitor->AssertCurrentThreadOwns();
     }
     MOZ_ASSERT(mPromise);
-    mPromise->Reject(aRejectValue, aMethodName);
-    mPromise = nullptr;
-  }
-  void Reject(typename PromiseType::RejectValueType&& aRejectValue,
-              const char* aMethodName)
-  {
-    if (mMonitor) {
-      mMonitor->AssertCurrentThreadOwns();
-    }
-    MOZ_ASSERT(mPromise);
-    mPromise->Reject(std::move(aRejectValue), aMethodName);
+    mPromise->Reject(std::forward<RejectValueType_>(aRejectValue), aMethodName);
     mPromise = nullptr;
   }
 
-  void RejectIfExists(const typename PromiseType::RejectValueType& aRejectValue,
-                      const char* aMethodName)
+  template<typename RejectValueType_>
+  void RejectIfExists(RejectValueType_&& aRejectValue, const char* aMethodName)
   {
     if (!IsEmpty()) {
-      Reject(aRejectValue, aMethodName);
-    }
-  }
-  void RejectIfExists(typename PromiseType::RejectValueType&& aRejectValue,
-                      const char* aMethodName)
-  {
-    if (!IsEmpty()) {
-      Reject(std::move(aRejectValue), aMethodName);
+      Reject(std::forward<RejectValueType_>(aRejectValue), aMethodName);
     }
   }
 
 private:
   Monitor* mMonitor;
   RefPtr<typename PromiseType::Private> mPromise;
 };