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

Side by Side Diff: base/callback.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: This old trap 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_CALLBACK_H_ 5 #ifndef BASE_CALLBACK_H_
6 #define BASE_CALLBACK_H_ 6 #define BASE_CALLBACK_H_
7 7
8 #include "base/callback_forward.h" 8 #include "base/callback_forward.h"
9 #include "base/callback_internal.h" 9 #include "base/callback_internal.h"
10 #include "base/template_util.h" 10 #include "base/template_util.h"
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 namespace internal { 360 namespace internal {
361 template <typename Runnable, typename RunType, typename BoundArgsType> 361 template <typename Runnable, typename RunType, typename BoundArgsType>
362 struct BindState; 362 struct BindState;
363 } // namespace internal 363 } // namespace internal
364 364
365 template <typename R, typename... Args> 365 template <typename R, typename... Args>
366 class Callback<R(Args...)> : public internal::CallbackBase { 366 class Callback<R(Args...)> : public internal::CallbackBase {
367 public: 367 public:
368 typedef R(RunType)(Args...); 368 typedef R(RunType)(Args...);
369 369
370 Callback() : CallbackBase(NULL) { } 370 Callback() {}
371 371
372 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT 372 // Note that this constructor CANNOT be explicit, and that Bind() CANNOT
373 // return the exact Callback<> type. See base/bind.h for details. 373 // return the exact Callback<> type. See base/bind.h for details.
374 template <typename Runnable, typename BindRunType, typename BoundArgsType> 374 template <typename Runnable, typename BindRunType, typename BoundArgsType>
375 Callback(internal::BindState<Runnable, BindRunType, 375 Callback(internal::BindState<Runnable, BindRunType,
376 BoundArgsType>* bind_state) 376 BoundArgsType>* bind_state)
377 : CallbackBase(bind_state) { 377 : CallbackBase(bind_state) {
378 // Force the assignment to a local variable of PolymorphicInvoke 378 // Force the assignment to a local variable of PolymorphicInvoke
379 // so the compiler will typecheck that the passed in Run() method has 379 // so the compiler will typecheck that the passed in Run() method has
380 // the correct type. 380 // the correct type.
381 PolymorphicInvoke invoke_func = 381 PolymorphicInvoke invoke_func =
382 &internal::BindState<Runnable, BindRunType, BoundArgsType> 382 &internal::BindState<Runnable, BindRunType, BoundArgsType>
383 ::InvokerType::Run; 383 ::InvokerType::Run;
384 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); 384 polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func);
385 } 385 }
386 386
387 bool Equals(const Callback& other) const { 387 bool Equals(const Callback& other) const {
388 return CallbackBase::Equals(other); 388 return CallbackBase::Equals(other);
389 } 389 }
390 390
391 R Run(typename internal::CallbackParamTraits<Args>::ForwardType... args) 391 R Run(typename internal::CallbackParamTraits<Args>::ForwardType... args)
392 const { 392 const {
393 PolymorphicInvoke f = 393 PolymorphicInvoke f =
394 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); 394 reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_);
395 395
396 return f(bind_state_.get(), internal::CallbackForward(args)...); 396 return f(bind_state_, internal::CallbackForward(args)...);
397 } 397 }
398 398
399 private: 399 private:
400 typedef R(*PolymorphicInvoke)( 400 typedef R(*PolymorphicInvoke)(
401 internal::BindStateBase*, 401 internal::BindStateBase*,
402 typename internal::CallbackParamTraits<Args>::ForwardType...); 402 typename internal::CallbackParamTraits<Args>::ForwardType...);
403 }; 403 };
404 404
405 // Syntactic sugar to make Callback<void(void)> easier to declare since it 405 // Syntactic sugar to make Callback<void(void)> easier to declare since it
406 // will be used in a lot of APIs with delayed execution. 406 // will be used in a lot of APIs with delayed execution.
407 typedef Callback<void(void)> Closure; 407 typedef Callback<void(void)> Closure;
408 408
409 } // namespace base 409 } // namespace base
410 410
411 #endif // BASE_CALLBACK_H_ 411 #endif // BASE_CALLBACK_H_
OLDNEW
« no previous file with comments | « base/bind_internal.h ('k') | base/callback_internal.h » ('j') | base/callback_internal.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698