Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1558)

Unified Diff: base/bind_internal.h

Issue 2322313002: Split BindStateBase ctor for non-cancellable Bind (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/callback_internal.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/bind_internal.h
diff --git a/base/bind_internal.h b/base/bind_internal.h
index 98a73908375394b8e03b70eea60b40741aba4b0d..724f0aa5696644f800f74cff8ee2ac8223299c71 100644
--- a/base/bind_internal.h
+++ b/base/bind_internal.h
@@ -378,6 +378,7 @@ struct BindState;
template <typename BindStateType, typename SFINAE = void>
struct CancellationChecker {
+ static constexpr bool is_cancellable = false;
static bool Run(const BindStateBase*) {
return false;
}
@@ -388,6 +389,7 @@ struct CancellationChecker<
BindState<Functor, BoundArgs...>,
typename std::enable_if<IsWeakMethod<FunctorTraits<Functor>::is_method,
BoundArgs...>::value>::type> {
+ static constexpr bool is_cancellable = true;
static bool Run(const BindStateBase* base) {
using BindStateType = BindState<Functor, BoundArgs...>;
const BindStateType* bind_state = static_cast<const BindStateType*>(base);
@@ -397,6 +399,7 @@ struct CancellationChecker<
template <typename Signature, typename... BoundArgs>
struct CancellationChecker<BindState<Callback<Signature>, BoundArgs...>> {
+ static constexpr bool is_cancellable = true;
static bool Run(const BindStateBase* base) {
using Functor = Callback<Signature>;
using BindStateType = BindState<Functor, BoundArgs...>;
@@ -410,10 +413,27 @@ struct CancellationChecker<BindState<Callback<Signature>, BoundArgs...>> {
// This stores all the state passed into Bind().
template <typename Functor, typename... BoundArgs>
struct BindState final : BindStateBase {
+ using IsCancellable = std::integral_constant<
+ bool, CancellationChecker<BindState>::is_cancellable>;
+
template <typename ForwardFunctor, typename... ForwardBoundArgs>
explicit BindState(BindStateBase::InvokeFuncStorage invoke_func,
ForwardFunctor&& functor,
ForwardBoundArgs&&... bound_args)
+ : BindState(IsCancellable(),
dcheng 2016/09/09 20:39:01 Is this a C++14ism? How does it work with our tool
dcheng 2016/09/09 20:39:27 Also, see https://github.com/llvm-mirror/libcxx/bl
+ invoke_func,
+ std::forward<ForwardFunctor>(functor),
+ std::forward<ForwardBoundArgs>(bound_args)...) {}
+
+ Functor functor_;
+ std::tuple<BoundArgs...> bound_args_;
+
+ private:
+ template <typename ForwardFunctor, typename... ForwardBoundArgs>
+ explicit BindState(std::true_type,
+ BindStateBase::InvokeFuncStorage invoke_func,
+ ForwardFunctor&& functor,
+ ForwardBoundArgs&&... bound_args)
: BindStateBase(invoke_func, &Destroy,
&CancellationChecker<BindState>::Run),
functor_(std::forward<ForwardFunctor>(functor)),
@@ -421,10 +441,17 @@ struct BindState final : BindStateBase {
DCHECK(!IsNull(functor_));
}
- Functor functor_;
- std::tuple<BoundArgs...> bound_args_;
+ template <typename ForwardFunctor, typename... ForwardBoundArgs>
+ explicit BindState(std::false_type,
+ BindStateBase::InvokeFuncStorage invoke_func,
+ ForwardFunctor&& functor,
+ ForwardBoundArgs&&... bound_args)
+ : BindStateBase(invoke_func, &Destroy),
+ functor_(std::forward<ForwardFunctor>(functor)),
+ bound_args_(std::forward<ForwardBoundArgs>(bound_args)...) {
+ DCHECK(!IsNull(functor_));
+ }
- private:
~BindState() {}
static void Destroy(BindStateBase* self) {
« no previous file with comments | « no previous file | base/callback_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698