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

Side by Side Diff: base/bind_internal.h

Issue 1129353003: Devirtualize base::BindState to save ~1% of Chrome's binary size (~1MB) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20150507-SizesExplorations
Patch Set: Keep the DCHECK Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/callback_internal.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_BIND_INTERNAL_H_ 5 #ifndef BASE_BIND_INTERNAL_H_
6 #define BASE_BIND_INTERNAL_H_ 6 #define BASE_BIND_INTERNAL_H_
7 7
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback_internal.h" 9 #include "base/callback_internal.h"
10 #include "base/memory/raw_scoped_refptr_mismatch_checker.h" 10 #include "base/memory/raw_scoped_refptr_mismatch_checker.h"
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 // RunType is type of the Run() function that the Invoker<> should use. 357 // RunType is type of the Run() function that the Invoker<> should use.
358 // Normally, this is the same as the RunType of the Runnable, but it can 358 // Normally, this is the same as the RunType of the Runnable, but it can
359 // be different if an adapter like IgnoreResult() has been used. 359 // be different if an adapter like IgnoreResult() has been used.
360 // 360 //
361 // BoundArgsType contains the storage type for all the bound arguments by 361 // BoundArgsType contains the storage type for all the bound arguments by
362 // (ab)using a function type. 362 // (ab)using a function type.
363 template <typename Runnable, typename RunType, typename BoundArgList> 363 template <typename Runnable, typename RunType, typename BoundArgList>
364 struct BindState; 364 struct BindState;
365 365
366 template <typename Runnable, 366 template <typename Runnable,
367 typename R, typename... Args, 367 typename R,
368 typename... Args,
368 typename... BoundArgs> 369 typename... BoundArgs>
369 struct BindState<Runnable, R(Args...), TypeList<BoundArgs...>> 370 struct BindState<Runnable, R(Args...), TypeList<BoundArgs...>> final
370 : public BindStateBase { 371 : public BindStateBase {
371 private: 372 private:
372 using StorageType = BindState<Runnable, R(Args...), TypeList<BoundArgs...>>; 373 using StorageType = BindState<Runnable, R(Args...), TypeList<BoundArgs...>>;
373 using RunnableType = Runnable; 374 using RunnableType = Runnable;
374 375
375 // true_type if Runnable is a method invocation and the first bound argument 376 // true_type if Runnable is a method invocation and the first bound argument
376 // is a WeakPtr. 377 // is a WeakPtr.
377 using IsWeakCall = 378 using IsWeakCall =
378 IsWeakMethod<HasIsMethodTag<Runnable>::value, BoundArgs...>; 379 IsWeakMethod<HasIsMethodTag<Runnable>::value, BoundArgs...>;
379 380
(...skipping 11 matching lines...) Expand all
391 InvokeHelper<IsWeakCall::value, R, Runnable, InvokeHelperArgs>; 392 InvokeHelper<IsWeakCall::value, R, Runnable, InvokeHelperArgs>;
392 393
393 using UnboundArgs = DropTypeListItem<sizeof...(BoundArgs), TypeList<Args...>>; 394 using UnboundArgs = DropTypeListItem<sizeof...(BoundArgs), TypeList<Args...>>;
394 395
395 public: 396 public:
396 using InvokerType = Invoker<BoundIndices, StorageType, Unwrappers, 397 using InvokerType = Invoker<BoundIndices, StorageType, Unwrappers,
397 InvokeHelperType, UnboundForwardRunType>; 398 InvokeHelperType, UnboundForwardRunType>;
398 using UnboundRunType = MakeFunctionType<R, UnboundArgs>; 399 using UnboundRunType = MakeFunctionType<R, UnboundArgs>;
399 400
400 BindState(const Runnable& runnable, const BoundArgs&... bound_args) 401 BindState(const Runnable& runnable, const BoundArgs&... bound_args)
401 : runnable_(runnable), ref_(bound_args...), bound_args_(bound_args...) {} 402 : BindStateBase(&Destroy),
403 runnable_(runnable),
404 ref_(bound_args...),
405 bound_args_(bound_args...) {}
402 406
403 RunnableType runnable_; 407 RunnableType runnable_;
404 MaybeScopedRefPtr<HasIsMethodTag<Runnable>::value, BoundArgs...> ref_; 408 MaybeScopedRefPtr<HasIsMethodTag<Runnable>::value, BoundArgs...> ref_;
405 Tuple<BoundArgs...> bound_args_; 409 Tuple<BoundArgs...> bound_args_;
406 410
407 private: 411 private:
408 ~BindState() override {} 412 ~BindState() {}
413
414 static void Destroy(BindStateBase* self) {
415 delete static_cast<BindState*>(self);
416 }
409 }; 417 };
410 418
411 } // namespace internal 419 } // namespace internal
412 } // namespace base 420 } // namespace base
413 421
414 #endif // BASE_BIND_INTERNAL_H_ 422 #endif // BASE_BIND_INTERNAL_H_
OLDNEW
« 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