зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1332785 - Optimize MozPromiseHolder::Resolve and Reject - r=jwwang
Instead of lvalues, MozPromiseHolder::Resolve and Reject now take either const& or && values of the expected types, to allow move semantics all the way to the ResolveOrRejectValue object. Note that we won't just take forwarding references of any type, as this could lead to implicit conversions by bypassing the 'explicit' marker of the value type constructors, like in bug 1331137. MozReview-Commit-ID: K0jeY6WTXI1 --HG-- extra : rebase_source : 7ee0fd1edfdeadb239f48c8b5b46fd54af3ec5d2
This commit is contained in:
Родитель
3fe21cfdba
Коммит
eb46a3cefe
|
@ -997,7 +997,7 @@ public:
|
|||
return p.forget();
|
||||
}
|
||||
|
||||
void Resolve(typename PromiseType::ResolveValueType aResolveValue,
|
||||
void Resolve(const typename PromiseType::ResolveValueType& aResolveValue,
|
||||
const char* aMethodName)
|
||||
{
|
||||
if (mMonitor) {
|
||||
|
@ -1007,17 +1007,33 @@ public:
|
|||
mPromise->Resolve(aResolveValue, aMethodName);
|
||||
mPromise = nullptr;
|
||||
}
|
||||
void Resolve(typename PromiseType::ResolveValueType&& aResolveValue,
|
||||
const char* aMethodName)
|
||||
{
|
||||
if (mMonitor) {
|
||||
mMonitor->AssertCurrentThreadOwns();
|
||||
}
|
||||
MOZ_ASSERT(mPromise);
|
||||
mPromise->Resolve(Move(aResolveValue), aMethodName);
|
||||
mPromise = nullptr;
|
||||
}
|
||||
|
||||
|
||||
void ResolveIfExists(typename PromiseType::ResolveValueType aResolveValue,
|
||||
void ResolveIfExists(const typename PromiseType::ResolveValueType& aResolveValue,
|
||||
const char* aMethodName)
|
||||
{
|
||||
if (!IsEmpty()) {
|
||||
Resolve(aResolveValue, aMethodName);
|
||||
}
|
||||
}
|
||||
void ResolveIfExists(typename PromiseType::ResolveValueType&& aResolveValue,
|
||||
const char* aMethodName)
|
||||
{
|
||||
if (!IsEmpty()) {
|
||||
Resolve(Move(aResolveValue), aMethodName);
|
||||
}
|
||||
}
|
||||
|
||||
void Reject(typename PromiseType::RejectValueType aRejectValue,
|
||||
void Reject(const typename PromiseType::RejectValueType& aRejectValue,
|
||||
const char* aMethodName)
|
||||
{
|
||||
if (mMonitor) {
|
||||
|
@ -1027,15 +1043,31 @@ public:
|
|||
mPromise->Reject(aRejectValue, aMethodName);
|
||||
mPromise = nullptr;
|
||||
}
|
||||
void Reject(typename PromiseType::RejectValueType&& aRejectValue,
|
||||
const char* aMethodName)
|
||||
{
|
||||
if (mMonitor) {
|
||||
mMonitor->AssertCurrentThreadOwns();
|
||||
}
|
||||
MOZ_ASSERT(mPromise);
|
||||
mPromise->Reject(Move(aRejectValue), aMethodName);
|
||||
mPromise = nullptr;
|
||||
}
|
||||
|
||||
|
||||
void RejectIfExists(typename PromiseType::RejectValueType aRejectValue,
|
||||
void RejectIfExists(const typename PromiseType::RejectValueType& aRejectValue,
|
||||
const char* aMethodName)
|
||||
{
|
||||
if (!IsEmpty()) {
|
||||
Reject(aRejectValue, aMethodName);
|
||||
}
|
||||
}
|
||||
void RejectIfExists(typename PromiseType::RejectValueType&& aRejectValue,
|
||||
const char* aMethodName)
|
||||
{
|
||||
if (!IsEmpty()) {
|
||||
Reject(Move(aRejectValue), aMethodName);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Monitor* mMonitor;
|
||||
|
|
Загрузка…
Ссылка в новой задаче