Skip to content

Commit

Permalink
Inline small constructors of CallbackBase
Browse files Browse the repository at this point in the history
Some of CallbackBase constructors has small bodies that is even smaller
than their size of the invocation set up.
This CL marks such constructors as inline for smaller binary size, and
reduces the stripped binary size of chrome on linux by 156kB.

Change-Id: I95999f4aebda6bc886dcfb66bc284ec0d42ccc86
Reviewed-on: https://chromium-review.googlesource.com/1113088
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570053}
  • Loading branch information
tzik authored and Commit Bot committed Jun 25, 2018
1 parent 5f7cb01 commit 787d420
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
12 changes: 1 addition & 11 deletions base/callback_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ BindStateBase::BindStateBase(InvokeFuncStorage polymorphic_invoke,
destructor_(destructor),
is_cancelled_(is_cancelled) {}

CallbackBase::CallbackBase(CallbackBase&& c) noexcept = default;
CallbackBase& CallbackBase::operator=(CallbackBase&& c) noexcept = default;
CallbackBase::CallbackBase(const CallbackBaseCopyable& c)
: bind_state_(c.bind_state_) {}
Expand Down Expand Up @@ -66,21 +65,12 @@ bool CallbackBase::EqualsInternal(const CallbackBase& other) const {
return bind_state_ == other.bind_state_;
}

CallbackBase::CallbackBase(BindStateBase* bind_state)
: bind_state_(bind_state ? AdoptRef(bind_state) : nullptr) {
DCHECK(!bind_state_.get() || bind_state_->HasOneRef());
}

CallbackBase::~CallbackBase() = default;

CallbackBaseCopyable::CallbackBaseCopyable(const CallbackBaseCopyable& c)
: CallbackBase(nullptr) {
CallbackBaseCopyable::CallbackBaseCopyable(const CallbackBaseCopyable& c) {
bind_state_ = c.bind_state_;
}

CallbackBaseCopyable::CallbackBaseCopyable(CallbackBaseCopyable&& c) noexcept =
default;

CallbackBaseCopyable& CallbackBaseCopyable::operator=(
const CallbackBaseCopyable& c) {
bind_state_ = c.bind_state_;
Expand Down
9 changes: 6 additions & 3 deletions base/callback_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class BASE_EXPORT BindStateBase
// CallbackBase<Copyable> uses CallbackBase<MoveOnly> for its implementation.
class BASE_EXPORT CallbackBase {
public:
CallbackBase(CallbackBase&& c) noexcept;
inline CallbackBase(CallbackBase&& c) noexcept;
CallbackBase& operator=(CallbackBase&& c) noexcept;

explicit CallbackBase(const CallbackBaseCopyable& c);
Expand Down Expand Up @@ -138,7 +138,7 @@ class BASE_EXPORT CallbackBase {

// Allow initializing of |bind_state_| via the constructor to avoid default
// initialization of the scoped_refptr.
explicit CallbackBase(BindStateBase* bind_state);
explicit inline CallbackBase(BindStateBase* bind_state);

InvokeFuncStorage polymorphic_invoke() const {
return bind_state_->polymorphic_invoke_;
Expand All @@ -153,12 +153,15 @@ class BASE_EXPORT CallbackBase {
};

constexpr CallbackBase::CallbackBase() = default;
CallbackBase::CallbackBase(CallbackBase&&) noexcept = default;
CallbackBase::CallbackBase(BindStateBase* bind_state)
: bind_state_(AdoptRef(bind_state)) {}

// CallbackBase<Copyable> is a direct base class of Copyable Callbacks.
class BASE_EXPORT CallbackBaseCopyable : public CallbackBase {
public:
CallbackBaseCopyable(const CallbackBaseCopyable& c);
CallbackBaseCopyable(CallbackBaseCopyable&& c) noexcept;
CallbackBaseCopyable(CallbackBaseCopyable&& c) noexcept = default;
CallbackBaseCopyable& operator=(const CallbackBaseCopyable& c);
CallbackBaseCopyable& operator=(CallbackBaseCopyable&& c) noexcept;

Expand Down

0 comments on commit 787d420

Please sign in to comment.