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

Side by Side Diff: tests/StackAllocatorTest.cpp

Issue 179343005: Add a class to allocate small objects w/o extra calls to new. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 9 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
« src/core/SkStackAllocator.h ('K') | « src/core/SkTemplatesPriv.h ('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
(Empty)
1 /*
2 * Copyright 2014 Google, Inc
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "Test.h"
tfarina 2014/02/27 17:33:15 could you keep this sorted?
scroggo 2014/03/05 20:25:52 Done.
9 #include "SkStackAllocator.h"
10 #include "SkTypes.h"
11
12 class CountingClass {
13 public:
14 CountingClass() {
15 kCount++;
16 }
17
18 ~CountingClass() {
19 kCount--;
20 }
21
22 static int GetCount() { return kCount; }
23
24 private:
25 static int kCount;
26 };
27
28 int CountingClass::kCount;
29
30 template<size_t size> void test_allocator(skiatest::Reporter* reporter) {
31 {
32 SkStackAllocator<size> alloc;
33 for (int i = 0; i < 99; ++i) {
34 void* buf = alloc.template reserveT<CountingClass>();
35 SkNEW_PLACEMENT(buf, CountingClass);
36 CountingClass* c = static_cast<CountingClass*>(buf);
37 REPORTER_ASSERT(reporter, c != NULL);
38 REPORTER_ASSERT(reporter, CountingClass::GetCount() == i+1);
39 }
40 }
41 REPORTER_ASSERT(reporter, CountingClass::GetCount() == 0);
42 }
43
44 DEF_TEST(StackAllocator, reporter) {
45 test_allocator<0>(reporter);
46 test_allocator<5>(reporter);
47 test_allocator<50>(reporter);
48 test_allocator<100>(reporter);
49 }
OLDNEW
« src/core/SkStackAllocator.h ('K') | « src/core/SkTemplatesPriv.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698