diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-21 19:23:44 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-21 19:23:44 +0000 |
commit | 7296f2763bd40e560466f09836c7208c42d90f94 (patch) | |
tree | 142a03c36f75f42738206355a029707ad88cdffc /base/bind_internal_win.h.pump | |
parent | 1fbbf963079bc977ea041b7e50ddf4666f6fec38 (diff) | |
download | chromium_src-7296f2763bd40e560466f09836c7208c42d90f94.zip chromium_src-7296f2763bd40e560466f09836c7208c42d90f94.tar.gz chromium_src-7296f2763bd40e560466f09836c7208c42d90f94.tar.bz2 |
Callback API Change: Reimplement Bind(); support IgnoreResult, full currying, and use less types.
The main API change IgnoreResult() and fully currying. See unittest for what the new API looks like. The rest of the changes are done to support that.
Previously, IgnoreReturn could not be used with WeakPtr<> Bind()s as it was applied after the fact to the Callback object. Now, IgnoreResult() wraps the function like Unretained().
As an incidental benefit, the new implementation gave us fully currying for free.
Also, the new implementation scales better when supporting higher arities of functions. The new type growth is:
(n^2 + 20n) / 2
as opposed to
(3n^2 + 17n) / 2
where n == arity.
For n = 6 and n=10, the new implementation has 81 and 155 templates respectively.
The old implementation had 105 and 235 templates respectively.
BUG=35233,98919,98542
TEST=existing unittests
Review URL: http://codereview.chromium.org/8483003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110975 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/bind_internal_win.h.pump')
-rw-r--r-- | base/bind_internal_win.h.pump | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/base/bind_internal_win.h.pump b/base/bind_internal_win.h.pump index 80ee37d..1d3b6b4 100644 --- a/base/bind_internal_win.h.pump +++ b/base/bind_internal_win.h.pump @@ -11,7 +11,7 @@ $var MAX_ARITY = 6 // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Specializations of FunctionTraits<> for Windows specific calling +// Specializations of RunnableAdapter<> for Windows specific calling // conventions. Please see base/bind_internal.h for more info. #ifndef BASE_BIND_INTERNAL_WIN_H_ @@ -26,8 +26,8 @@ $var MAX_ARITY = 6 namespace base { namespace internal { -template <typename Sig> -struct FunctionTraits; +template <typename Functor> +class RunnableAdapter; $range ARITY 0..MAX_ARITY $for ARITY [[ @@ -35,42 +35,40 @@ $range ARG 1..ARITY // __stdcall Function: Arity $(ARITY). template <typename R[[]] -$if ARITY > 0[[, ]] $for ARG , [[typename X$(ARG)]]> -struct FunctionTraits<R(__stdcall *)($for ARG , [[X$(ARG)]])> { - typedef R (*NormalizedSig)($for ARG , [[X$(ARG)]]); - typedef false_type IsMethod; +$if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]> +class RunnableAdapter<R(__stdcall *)($for ARG , [[A$(ARG)]])> { + public: + typedef R (RunType)($for ARG , [[A$(ARG)]]); - typedef R Return; + explicit RunnableAdapter(R(__stdcall *function)($for ARG , [[A$(ARG)]])) + : function_(function) { + } -$if ARITY > 0 [[ + R Run($for ARG , [[typename CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) { + return function_($for ARG , [[a$(ARG)]]); + } - // Target type for each bound parameter. - -$for ARG [[ - typedef X$(ARG) B$(ARG); - -]] $$ for ARG -]] $$ if ARITY > 0 + private: + R (__stdcall *function_)($for ARG , [[A$(ARG)]]); }; // __fastcall Function: Arity $(ARITY). template <typename R[[]] -$if ARITY > 0[[, ]] $for ARG , [[typename X$(ARG)]]> -struct FunctionTraits<R(__fastcall *)($for ARG , [[X$(ARG)]])> { - typedef R (*NormalizedSig)($for ARG , [[X$(ARG)]]); - typedef false_type IsMethod; - - typedef R Return; - -$if ARITY > 0 [[ +$if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]> +class RunnableAdapter<R(__fastcall *)($for ARG , [[A$(ARG)]])> { + public: + typedef R (RunType)($for ARG , [[A$(ARG)]]); - // Target type for each bound parameter. + explicit RunnableAdapter(R(__fastcall *function)($for ARG , [[A$(ARG)]])) + : function_(function) { + } -$for ARG [[ - typedef X$(ARG) B$(ARG); + R Run($for ARG , [[typename CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) { + return function_($for ARG , [[a$(ARG)]]); + } -]] $$ for ARG -]] $$ if ARITY > 0 + private: + R (__fastcall *function_)($for ARG , [[A$(ARG)]]); }; ]] $$for ARITY |