From 6ba91a9df7cb8e3fee614639c1ecb5af3f68f807 Mon Sep 17 00:00:00 2001 From: tzik Date: Mon, 15 Feb 2016 12:51:34 -0800 Subject: Use Perfect Forwarding where possible in bind_internals.h Most of CallbackForward and CallbackParamTraits in bind_internals.h can be replaced with Universal References and Perfect Forwarding. This CL applies the replacement as possible as there's no runtime cost. BUG=554299 Review URL: https://codereview.chromium.org/1701633002 Cr-Commit-Position: refs/heads/master@{#375488} --- base/bind_internal.h | 59 ++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/base/bind_internal.h b/base/bind_internal.h index ce6b5d6..90889d5 100644 --- a/base/bind_internal.h +++ b/base/bind_internal.h @@ -154,8 +154,9 @@ class RunnableAdapter { : function_(function) { } - R Run(typename CallbackParamTraits::ForwardType... args) { - return function_(CallbackForward(args)...); + template + R Run(RunArgs&&... args) { + return function_(std::forward(args)...); } private: @@ -175,8 +176,9 @@ class RunnableAdapter { : method_(method) { } - R Run(T* object, typename CallbackParamTraits::ForwardType... args) { - return (object->*method_)(CallbackForward(args)...); + template + R Run(T* object, RunArgs&&... args) { + return (object->*method_)(std::forward(args)...); } private: @@ -194,9 +196,9 @@ class RunnableAdapter { : method_(method) { } - R Run(const T* object, - typename CallbackParamTraits::ForwardType... args) { - return (object->*method_)(CallbackForward(args)...); + template + R Run(const T* object, RunArgs&&... args) { + return (object->*method_)(std::forward(args)...); } private: @@ -281,38 +283,42 @@ MakeRunnable(const Callback& t) { // // WeakCalls similarly need special syntax that is applied to the first // argument to check if they should no-op themselves. -template +template struct InvokeHelper; -template -struct InvokeHelper> { - static ReturnType MakeItSo(Runnable runnable, Args... args) { - return runnable.Run(CallbackForward(args)...); +template +struct InvokeHelper { + template + static ReturnType MakeItSo(Runnable runnable, RunArgs&&... args) { + return runnable.Run(std::forward(args)...); } }; -template -struct InvokeHelper> { - static void MakeItSo(Runnable runnable, Args... args) { - runnable.Run(CallbackForward(args)...); +template +struct InvokeHelper { + template + static void MakeItSo(Runnable runnable, RunArgs&&... args) { + runnable.Run(std::forward(args)...); } }; -template -struct InvokeHelper> { - static void MakeItSo(Runnable runnable, BoundWeakPtr weak_ptr, Args... args) { +template +struct InvokeHelper { + template + static void MakeItSo(Runnable runnable, + BoundWeakPtr weak_ptr, + RunArgs&&... args) { if (!weak_ptr.get()) { return; } - runnable.Run(weak_ptr.get(), CallbackForward(args)...); + runnable.Run(weak_ptr.get(), std::forward(args)...); } }; #if !defined(_MSC_VER) -template -struct InvokeHelper { +template +struct InvokeHelper { // WeakCalls are only supported for functions with a void return type. // Otherwise, the function result would be undefined if the the WeakPtr<> // is invalidated. @@ -388,12 +394,7 @@ struct BindState final sizeof...(BoundArgs), TypeList::ForwardType...>>; using UnboundForwardRunType = MakeFunctionType; - - using InvokeHelperArgs = ConcatTypeLists< - TypeList::ForwardType...>, - UnboundForwardArgs>; - using InvokeHelperType = - InvokeHelper; + using InvokeHelperType = InvokeHelper; using UnboundArgs = DropTypeListItem>; -- cgit v1.1