Chromium Code Reviews| Index: base/callback.h |
| diff --git a/base/callback.h b/base/callback.h |
| index 3bf0008b6d33bf73e075f502523327817ddb1345..46c57527a1afdd8c3ca3174a6f1f976979724662 100644 |
| --- a/base/callback.h |
| +++ b/base/callback.h |
| @@ -386,18 +386,24 @@ class Callback<R(Args...)> : public internal::CallbackBase { |
| return CallbackBase::Equals(other); |
| } |
| - R Run(typename internal::CallbackParamTraits<Args>::ForwardType... args) |
| - const { |
| + // Run() makes an extra copy of an argument comparing to the direct call |
| + // if an item of |args| is passed-by-value and a copyable-but-not-movable. |
|
dcheng
2016/03/02 23:00:57
Nit: Run() makes an extra copy compared to directl
tzik
2016/03/03 18:53:19
Done.
|
| + // I.e. below copies CopyableNonMovableType twice. |
|
dcheng
2016/03/02 23:00:57
Nit: i.e.
tzik
2016/03/03 18:53:19
Done.
|
| + // void F(CopyableNonMovableType) {} |
| + // Bind(&F).Run(CopyableNonMovableType()); |
| + // |
| + // We can not fully apply Perfect Forwarding idiom to the callchain from |
| + // Callback::Run() to the target function. Perfect Forwarding requires the |
| + // information how the caller passed the argument, but we have to fix the type |
| + // of |f| before we know how the arguments of Callback::Run() are passed. |
|
dcheng
2016/03/02 23:00:57
Nit: Perfect Forwarding requires knowing how the c
tzik
2016/03/03 18:53:19
Done, but slightly modified.
We can template Callb
|
| + R Run(Args... args) const { |
| PolymorphicInvoke f = |
| reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); |
| - |
| - return f(bind_state_.get(), internal::CallbackForward(args)...); |
| + return f(bind_state_.get(), std::forward<Args>(args)...); |
| } |
| private: |
| - using PolymorphicInvoke = |
| - R(*)(internal::BindStateBase*, |
| - typename internal::CallbackParamTraits<Args>::ForwardType...); |
| + using PolymorphicInvoke = R (*)(internal::BindStateBase*, Args&&...); |
| }; |
| } // namespace base |