diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-18 23:29:31 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-18 23:29:31 +0000 |
commit | 59eff91b6b042f8389c4af756968a93407bf7c24 (patch) | |
tree | ccfcfb02ef774ffd178d948275dd8e4f07f30bf7 /base | |
parent | c1640b0e400cca2f6d6d223703dcafe46a48a7af (diff) | |
download | chromium_src-59eff91b6b042f8389c4af756968a93407bf7c24.zip chromium_src-59eff91b6b042f8389c4af756968a93407bf7c24.tar.gz chromium_src-59eff91b6b042f8389c4af756968a93407bf7c24.tar.bz2 |
Callback: De-inline CallbackBase, and move to callback_helpers -> callback_internal.h
We can re-inline later if it starts being an issue.
BUG=none
TEST=unit-tests
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=75443
Review URL: http://codereview.chromium.org/6542026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75464 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/base.gypi | 3 | ||||
-rw-r--r-- | base/bind.h | 2 | ||||
-rw-r--r-- | base/bind.h.pump | 2 | ||||
-rw-r--r-- | base/bind_internal.h | 2 | ||||
-rw-r--r-- | base/bind_internal.h.pump | 2 | ||||
-rw-r--r-- | base/callback.h | 45 | ||||
-rw-r--r-- | base/callback.h.pump | 45 | ||||
-rw-r--r-- | base/callback_internal.cc | 36 | ||||
-rw-r--r-- | base/callback_internal.h (renamed from base/callback_helpers.h) | 37 | ||||
-rw-r--r-- | base/callback_unittest.cc | 2 |
10 files changed, 79 insertions, 97 deletions
diff --git a/base/base.gypi b/base/base.gypi index 79ba5f4..13cb1ba 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -42,7 +42,8 @@ 'bits.h', 'bzip2_error_handler.cc', 'callback.h', - 'callback_helpers.h', + 'callback_internal.cc', + 'callback_internal.h', 'callback_old.h', 'command_line.cc', 'command_line.h', diff --git a/base/bind.h b/base/bind.h index c23af2e..cd9eb19 100644 --- a/base/bind.h +++ b/base/bind.h @@ -12,7 +12,7 @@ #pragma once #include "base/bind_internal.h" -#include "base/callback_helpers.h" +#include "base/callback_internal.h" // See base/callback.h for how to use these functions. // diff --git a/base/bind.h.pump b/base/bind.h.pump index fc7f246..62b313f 100644 --- a/base/bind.h.pump +++ b/base/bind.h.pump @@ -16,7 +16,7 @@ $var MAX_ARITY = 6 #pragma once #include "base/bind_internal.h" -#include "base/callback_helpers.h" +#include "base/callback_internal.h" // See base/callback.h for how to use these functions. // diff --git a/base/bind_internal.h b/base/bind_internal.h index 62f2050..dd8afde 100644 --- a/base/bind_internal.h +++ b/base/bind_internal.h @@ -12,7 +12,7 @@ #pragma once #include "base/bind_helpers.h" -#include "base/callback_helpers.h" +#include "base/callback_internal.h" #include "base/template_util.h" namespace base { diff --git a/base/bind_internal.h.pump b/base/bind_internal.h.pump index 132b0db..6fd95fe 100644 --- a/base/bind_internal.h.pump +++ b/base/bind_internal.h.pump @@ -16,7 +16,7 @@ $var MAX_ARITY = 6 #pragma once #include "base/bind_helpers.h" -#include "base/callback_helpers.h" +#include "base/callback_internal.h" #include "base/template_util.h" namespace base { diff --git a/base/callback.h b/base/callback.h index 9e43afb..9c76aa5 100644 --- a/base/callback.h +++ b/base/callback.h @@ -11,7 +11,7 @@ #define BASE_CALLBACK_H_ #pragma once -#include "base/callback_helpers.h" +#include "base/callback_internal.h" #include "base/callback_old.h" // New, super-duper, unified Callback system. This will eventually replace @@ -212,49 +212,6 @@ namespace base { -namespace internal { - -// Holds the methods that don't require specialization to reduce template bloat. -class CallbackBase { - public: - // Returns true if Callback is null (doesn't refer to anything). - bool is_null() const { - return invoker_storage_.get() == NULL; - } - - // Returns the Callback into an uninitalized state. - void Reset() { - invoker_storage_ = NULL; - polymorphic_invoke_ = NULL; - } - - bool Equals(const CallbackBase& other) const { - return invoker_storage_.get() == other.invoker_storage_.get() && - polymorphic_invoke_ == other.polymorphic_invoke_; - } - - protected: - // In C++, it is safe to cast function pointers to function pointers of - // another type. It is not okay to use void*. We create a InvokeFuncStorage - // that that can store our function pointer, and then cast it back to - // the original type on usage. - typedef void(*InvokeFuncStorage)(void); - - CallbackBase(InvokeFuncStorage polymorphic_invoke, - scoped_refptr<InvokerStorageBase>* invoker_storage) - : polymorphic_invoke_(polymorphic_invoke) { - if (invoker_storage) { - invoker_storage_.swap(*invoker_storage); - } - } - - scoped_refptr<InvokerStorageBase> invoker_storage_; - InvokeFuncStorage polymorphic_invoke_; -}; - -} // namespace internal - - // First, we forward declare the Callback class template. This informs the // compiler that the template only has 1 type parameter which is the function // signature that the Callback is representing. diff --git a/base/callback.h.pump b/base/callback.h.pump index 19b7987..2efe0c5 100644 --- a/base/callback.h.pump +++ b/base/callback.h.pump @@ -15,7 +15,7 @@ $var MAX_ARITY = 6 #define BASE_CALLBACK_H_ #pragma once -#include "base/callback_helpers.h" +#include "base/callback_internal.h" #include "base/callback_old.h" // New, super-duper, unified Callback system. This will eventually replace @@ -216,49 +216,6 @@ $var MAX_ARITY = 6 namespace base { -namespace internal { - -// Holds the methods that don't require specialization to reduce template bloat. -class CallbackBase { - public: - // Returns true if Callback is null (doesn't refer to anything). - bool is_null() const { - return invoker_storage_.get() == NULL; - } - - // Returns the Callback into an uninitalized state. - void Reset() { - invoker_storage_ = NULL; - polymorphic_invoke_ = NULL; - } - - bool Equals(const CallbackBase& other) const { - return invoker_storage_.get() == other.invoker_storage_.get() && - polymorphic_invoke_ == other.polymorphic_invoke_; - } - - protected: - // In C++, it is safe to cast function pointers to function pointers of - // another type. It is not okay to use void*. We create a InvokeFuncStorage - // that that can store our function pointer, and then cast it back to - // the original type on usage. - typedef void(*InvokeFuncStorage)(void); - - CallbackBase(InvokeFuncStorage polymorphic_invoke, - scoped_refptr<InvokerStorageBase>* invoker_storage) - : polymorphic_invoke_(polymorphic_invoke) { - if (invoker_storage) { - invoker_storage_.swap(*invoker_storage); - } - } - - scoped_refptr<InvokerStorageBase> invoker_storage_; - InvokeFuncStorage polymorphic_invoke_; -}; - -} // namespace internal - - // First, we forward declare the Callback class template. This informs the // compiler that the template only has 1 type parameter which is the function // signature that the Callback is representing. diff --git a/base/callback_internal.cc b/base/callback_internal.cc new file mode 100644 index 0000000..d9d1e6f --- /dev/null +++ b/base/callback_internal.cc @@ -0,0 +1,36 @@ +// 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. + +#include "base/callback_internal.h" + +namespace base { +namespace internal { + +bool CallbackBase::is_null() const { + return invoker_storage_.get() == NULL; +} + +void CallbackBase::Reset() { + invoker_storage_ = NULL; + polymorphic_invoke_ = NULL; +} + +bool CallbackBase::Equals(const CallbackBase& other) const { + return invoker_storage_.get() == other.invoker_storage_.get() && + polymorphic_invoke_ == other.polymorphic_invoke_; +} + +CallbackBase::CallbackBase(InvokeFuncStorage polymorphic_invoke, + scoped_refptr<InvokerStorageBase>* invoker_storage) + : polymorphic_invoke_(polymorphic_invoke) { + if (invoker_storage) { + invoker_storage_.swap(*invoker_storage); + } +} + +CallbackBase::~CallbackBase() { +} + +} // namespace base +} // namespace internal diff --git a/base/callback_helpers.h b/base/callback_internal.h index 86b0df1..4f1d3c3 100644 --- a/base/callback_helpers.h +++ b/base/callback_internal.h @@ -5,8 +5,8 @@ // This file contains utility functions and classes that help the // implementation, and management of the Callback objects. -#ifndef BASE_CALLBACK_HELPERS_H_ -#define BASE_CALLBACK_HELPERS_H_ +#ifndef BASE_CALLBACK_INTERNAL_H_ +#define BASE_CALLBACK_INTERNAL_H_ #pragma once #include "base/ref_counted.h" @@ -49,7 +49,38 @@ InvokerStorageHolder<T> MakeInvokerStorageHolder(T* o) { return InvokerStorageHolder<T>(o); } +// Holds the Callback methods that don't require specialization to reduce +// template bloat. +class CallbackBase { + public: + // Returns true if Callback is null (doesn't refer to anything). + bool is_null() const; + + // Returns the Callback into an uninitalized state. + void Reset(); + + bool Equals(const CallbackBase& other) const; + + protected: + // In C++, it is safe to cast function pointers to function pointers of + // another type. It is not okay to use void*. We create a InvokeFuncStorage + // that that can store our function pointer, and then cast it back to + // the original type on usage. + typedef void(*InvokeFuncStorage)(void); + + CallbackBase(InvokeFuncStorage polymorphic_invoke, + scoped_refptr<InvokerStorageBase>* invoker_storage); + + // Force the destructor to be instaniated inside this translation unit so + // that our subclasses will not get inlined versions. Avoids more template + // bloat. + ~CallbackBase(); + + scoped_refptr<InvokerStorageBase> invoker_storage_; + InvokeFuncStorage polymorphic_invoke_; +}; + } // namespace internal } // namespace base -#endif // BASE_CALLBACK_HELPERS_H_ +#endif // BASE_CALLBACK_INTERNAL_H_ diff --git a/base/callback_unittest.cc b/base/callback_unittest.cc index bf2b606..e41b399 100644 --- a/base/callback_unittest.cc +++ b/base/callback_unittest.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. #include "base/callback.h" -#include "base/callback_helpers.h" +#include "base/callback_internal.h" #include "base/scoped_ptr.h" #include "testing/gtest/include/gtest/gtest.h" |