From f44c2f8d3e188f4e4bca155d34ab5f6edbf0964a Mon Sep 17 00:00:00 2001 From: tzik Date: Wed, 8 Mar 2017 00:41:15 -0800 Subject: [PATCH] Avoid copy on move-conversion from RepeatingCallback to OnceCallback CallbackBase didn't have the move-conversion constructor and move-conversion assignment. That causes an extra copy on the conversion from rvalue RepeatingCallback to OnceCallback. Review-Url: https://codereview.chromium.org/2740703002 Cr-Commit-Position: refs/heads/master@{#455404} --- base/callback_internal.cc | 10 ++++++++++ base/callback_internal.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/base/callback_internal.cc b/base/callback_internal.cc index 4afd567f0fe32e..4330e9cce511a5 100644 --- a/base/callback_internal.cc +++ b/base/callback_internal.cc @@ -54,6 +54,16 @@ CallbackBase& CallbackBase::operator=( return *this; } +CallbackBase::CallbackBase( + CallbackBase&& c) + : bind_state_(std::move(c.bind_state_)) {} + +CallbackBase& CallbackBase::operator=( + CallbackBase&& c) { + bind_state_ = std::move(c.bind_state_); + return *this; +} + void CallbackBase::Reset() { // NULL the bind_state_ last, since it may be holding the last ref to whatever // object owns us, and we may be deleted after that. diff --git a/base/callback_internal.h b/base/callback_internal.h index f7501f96c5d737..d6dcfeb3c02862 100644 --- a/base/callback_internal.h +++ b/base/callback_internal.h @@ -82,6 +82,9 @@ class BASE_EXPORT CallbackBase { explicit CallbackBase(const CallbackBase& c); CallbackBase& operator=(const CallbackBase& c); + explicit CallbackBase(CallbackBase&& c); + CallbackBase& operator=(CallbackBase&& c); + // Returns true if Callback is null (doesn't refer to anything). bool is_null() const { return bind_state_.get() == NULL; } explicit operator bool() const { return !is_null(); }