Skip to content

Commit

Permalink
Avoid copy on move-conversion from RepeatingCallback to OnceCallback
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
tzik authored and Commit bot committed Mar 8, 2017
1 parent 539c908 commit f44c2f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions base/callback_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ CallbackBase<CopyMode::MoveOnly>& CallbackBase<CopyMode::MoveOnly>::operator=(
return *this;
}

CallbackBase<CopyMode::MoveOnly>::CallbackBase(
CallbackBase<CopyMode::Copyable>&& c)
: bind_state_(std::move(c.bind_state_)) {}

CallbackBase<CopyMode::MoveOnly>& CallbackBase<CopyMode::MoveOnly>::operator=(
CallbackBase<CopyMode::Copyable>&& c) {
bind_state_ = std::move(c.bind_state_);
return *this;
}

void CallbackBase<CopyMode::MoveOnly>::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.
Expand Down
3 changes: 3 additions & 0 deletions base/callback_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class BASE_EXPORT CallbackBase<CopyMode::MoveOnly> {
explicit CallbackBase(const CallbackBase<CopyMode::Copyable>& c);
CallbackBase& operator=(const CallbackBase<CopyMode::Copyable>& c);

explicit CallbackBase(CallbackBase<CopyMode::Copyable>&& c);
CallbackBase& operator=(CallbackBase<CopyMode::Copyable>&& 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(); }
Expand Down

0 comments on commit f44c2f8

Please sign in to comment.