summaryrefslogtreecommitdiffstats
path: root/base/callback.h
diff options
context:
space:
mode:
authorajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-28 22:13:54 +0000
committerajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-28 22:13:54 +0000
commitfccef1559e02b001c69a0d35ad960e37dcbfd650 (patch)
treeb3ddaa715bf24e5d44a134b7298f39e59b2c1f27 /base/callback.h
parent485c5558393ab8fa34c580eed539a37d9d8f1450 (diff)
downloadchromium_src-fccef1559e02b001c69a0d35ad960e37dcbfd650.zip
chromium_src-fccef1559e02b001c69a0d35ad960e37dcbfd650.tar.gz
chromium_src-fccef1559e02b001c69a0d35ad960e37dcbfd650.tar.bz2
Increase Bind/Callback Arity from 6 -> 7.
A few functions need this and the expected compile-speed impact is low. We should be careful when raising this number higher. If you're binding a function that has more parameters than this supports, consider refactoring your API to use a parameter struct or something. Template equation: (n^2 + 26n) / 2 Template growth: 96 -> 116 types. BUG=98542 TEST=try bots Review URL: http://codereview.chromium.org/8728010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111788 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/callback.h')
-rw-r--r--base/callback.h64
1 files changed, 62 insertions, 2 deletions
diff --git a/base/callback.h b/base/callback.h
index 6844cc5..16e3ee6 100644
--- a/base/callback.h
+++ b/base/callback.h
@@ -3,7 +3,6 @@
// DO NOT EDIT BY HAND!!!
-
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -227,7 +226,7 @@ namespace base {
// compiler that the template only has 1 type parameter which is the function
// signature that the Callback is representing.
//
-// After this, create template specializations for 0-6 parameters. Note that
+// After this, create template specializations for 0-7 parameters. Note that
// even though the template typelist grows, the specialization still
// only has one type: the function signature.
template <typename Sig>
@@ -573,6 +572,67 @@ class Callback<R(A1, A2, A3, A4, A5, A6)> : public internal::CallbackBase {
};
+template <typename R, typename A1, typename A2, typename A3, typename A4,
+ typename A5, typename A6, typename A7>
+class Callback<R(A1, A2, A3, A4, A5, A6, A7)> : public internal::CallbackBase {
+ public:
+ typedef R(RunType)(A1, A2, A3, A4, A5, A6, A7);
+
+ Callback() : CallbackBase(NULL, NULL) { }
+
+ // We pass BindStateHolder by const ref to avoid incurring an
+ // unnecessary AddRef/Unref pair even though we will modify the object.
+ // We cannot use a normal reference because the compiler will warn
+ // since this is often used on a return value, which is a temporary.
+ //
+ // Note that this constructor CANNOT be explicit, and that Bind() CANNOT
+ // return the exact Callback<> type. See base/bind.h for details.
+ template <typename T>
+ Callback(const internal::BindStateHolder<T>& bind_state_holder)
+ : CallbackBase(NULL, &bind_state_holder.bind_state_) {
+ // Force the assignment to a location variable of PolymorphicInvoke
+ // so the compiler will typecheck that the passed in Run() method has
+ // the correct type.
+ PolymorphicInvoke invoke_func = &T::InvokerType::Run;
+ polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func);
+ }
+
+ bool Equals(const Callback& other) const {
+ return CallbackBase::Equals(other);
+ }
+
+ R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1,
+ typename internal::CallbackParamTraits<A2>::ForwardType a2,
+ typename internal::CallbackParamTraits<A3>::ForwardType a3,
+ typename internal::CallbackParamTraits<A4>::ForwardType a4,
+ typename internal::CallbackParamTraits<A5>::ForwardType a5,
+ typename internal::CallbackParamTraits<A6>::ForwardType a6,
+ typename internal::CallbackParamTraits<A7>::ForwardType a7) const {
+ PolymorphicInvoke f =
+ reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_);
+
+ return f(bind_state_.get(), a1,
+ a2,
+ a3,
+ a4,
+ a5,
+ a6,
+ a7);
+ }
+
+ private:
+ typedef R(*PolymorphicInvoke)(
+ internal::BindStateBase*,
+ typename internal::CallbackParamTraits<A1>::ForwardType,
+ typename internal::CallbackParamTraits<A2>::ForwardType,
+ typename internal::CallbackParamTraits<A3>::ForwardType,
+ typename internal::CallbackParamTraits<A4>::ForwardType,
+ typename internal::CallbackParamTraits<A5>::ForwardType,
+ typename internal::CallbackParamTraits<A6>::ForwardType,
+ typename internal::CallbackParamTraits<A7>::ForwardType);
+
+};
+
// Syntactic sugar to make Callbacks<void(void)> easier to declare since it
// will be used in a lot of APIs with delayed execution.