Bug 1514908 - Reduce deep copies of the closures passed to this function. r=baku

By taking an rvalue reference and using std::move more aggressively, we can
avoid at least two copies of these closures, which avoids a bit of atomic
refcounting.

Differential Revision: https://phabricator.services.mozilla.com/D14807

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Blake Kaplan 2018-12-18 18:52:26 +00:00
Родитель 618fd67694
Коммит f9cc1d1c09
2 изменённых файлов: 8 добавлений и 8 удалений

Просмотреть файл

@ -89,8 +89,8 @@ void WorkerRef::Notify() {
return;
}
std::function<void()> callback = mCallback;
mCallback = nullptr;
std::function<void()> callback = std::move(mCallback);
MOZ_ASSERT(!mCallback);
callback();
}
@ -99,7 +99,7 @@ void WorkerRef::Notify() {
// WeakWorkerRef
/* static */ already_AddRefed<WeakWorkerRef> WeakWorkerRef::Create(
WorkerPrivate* aWorkerPrivate, const std::function<void()>& aCallback) {
WorkerPrivate* aWorkerPrivate, std::function<void()>&& aCallback) {
MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread();
@ -113,7 +113,7 @@ void WorkerRef::Notify() {
}
ref->mHolder = std::move(holder);
ref->mCallback = aCallback;
ref->mCallback = std::move(aCallback);
return ref.forget();
}
@ -144,7 +144,7 @@ WorkerPrivate* WeakWorkerRef::GetUnsafePrivate() const {
/* static */ already_AddRefed<StrongWorkerRef> StrongWorkerRef::Create(
WorkerPrivate* aWorkerPrivate, const char* aName,
const std::function<void()>& aCallback) {
std::function<void()>&& aCallback) {
MOZ_ASSERT(aWorkerPrivate);
MOZ_ASSERT(aName);
@ -158,7 +158,7 @@ WorkerPrivate* WeakWorkerRef::GetUnsafePrivate() const {
}
ref->mHolder = std::move(holder);
ref->mCallback = aCallback;
ref->mCallback = std::move(aCallback);
return ref.forget();
}

Просмотреть файл

@ -108,7 +108,7 @@ class WeakWorkerRef final : public WorkerRef {
public:
static already_AddRefed<WeakWorkerRef> Create(
WorkerPrivate* aWorkerPrivate,
const std::function<void()>& aCallback = nullptr);
std::function<void()>&& aCallback = nullptr);
WorkerPrivate* GetPrivate() const;
@ -127,7 +127,7 @@ class StrongWorkerRef final : public WorkerRef {
public:
static already_AddRefed<StrongWorkerRef> Create(
WorkerPrivate* aWorkerPrivate, const char* aName,
const std::function<void()>& aCallback = nullptr);
std::function<void()>&& aCallback = nullptr);
WorkerPrivate* Private() const;