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

Side by Side Diff: base/callback_unittest.cc

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 | « base/callback_internal.cc ('k') | no next file » | 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) 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 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/callback_internal.h" 8 #include "base/callback_internal.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 17 matching lines...) Expand all
28 28
29 // White-box testpoints to inject into a Callback<> object for checking 29 // White-box testpoints to inject into a Callback<> object for checking
30 // comparators and emptiness APIs. Use a BindState that is specialized 30 // comparators and emptiness APIs. Use a BindState that is specialized
31 // based on a type we declared in the anonymous namespace above to remove any 31 // based on a type we declared in the anonymous namespace above to remove any
32 // chance of colliding with another instantiation and breaking the 32 // chance of colliding with another instantiation and breaking the
33 // one-definition-rule. 33 // one-definition-rule.
34 template <> 34 template <>
35 struct BindState<void(void), void(void), void(FakeInvoker)> 35 struct BindState<void(void), void(void), void(FakeInvoker)>
36 : public BindStateBase { 36 : public BindStateBase {
37 public: 37 public:
38 BindState() : BindStateBase(&Destroy) {}
38 typedef FakeInvoker InvokerType; 39 typedef FakeInvoker InvokerType;
39 private: 40 private:
40 ~BindState() override {} 41 ~BindState() {}
42 static void Destroy(BindStateBase* self) {
43 delete static_cast<BindState*>(self);
44 }
41 }; 45 };
42 46
43 template <> 47 template <>
44 struct BindState<void(void), void(void), 48 struct BindState<void(void), void(void),
45 void(FakeInvoker, FakeInvoker)> 49 void(FakeInvoker, FakeInvoker)>
46 : public BindStateBase { 50 : public BindStateBase {
47 public: 51 public:
52 BindState() : BindStateBase(&Destroy) {}
48 typedef FakeInvoker InvokerType; 53 typedef FakeInvoker InvokerType;
49 private: 54 private:
50 ~BindState() override {} 55 ~BindState() {}
56 static void Destroy(BindStateBase* self) {
57 delete static_cast<BindState*>(self);
58 }
51 }; 59 };
52 } // namespace internal 60 } // namespace internal
53 61
54 namespace { 62 namespace {
55 63
56 typedef internal::BindState<void(void), void(void), void(FakeInvoker)> 64 typedef internal::BindState<void(void), void(void), void(FakeInvoker)>
57 FakeBindState1; 65 FakeBindState1;
58 typedef internal::BindState<void(void), void(void), 66 typedef internal::BindState<void(void), void(void),
59 void(FakeInvoker, FakeInvoker)> 67 void(FakeInvoker, FakeInvoker)>
60 FakeBindState2; 68 FakeBindState2;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 183
176 TEST_F(CallbackTest, CallbackHasLastRefOnContainingObject) { 184 TEST_F(CallbackTest, CallbackHasLastRefOnContainingObject) {
177 bool deleted = false; 185 bool deleted = false;
178 CallbackOwner* owner = new CallbackOwner(&deleted); 186 CallbackOwner* owner = new CallbackOwner(&deleted);
179 owner->Reset(); 187 owner->Reset();
180 ASSERT_TRUE(deleted); 188 ASSERT_TRUE(deleted);
181 } 189 }
182 190
183 } // namespace 191 } // namespace
184 } // namespace base 192 } // namespace base
OLDNEW
« no previous file with comments | « base/callback_internal.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698