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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
« src/core/SkStackAllocator.h ('K') | « src/core/SkTemplatesPriv.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/StackAllocatorTest.cpp
diff --git a/tests/StackAllocatorTest.cpp b/tests/StackAllocatorTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..bf16c584f84959a7e3b9e06c1e04a1e130de49d9
--- /dev/null
+++ b/tests/StackAllocatorTest.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2014 Google, Inc
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Test.h"
tfarina 2014/02/27 17:33:15 could you keep this sorted?
scroggo 2014/03/05 20:25:52 Done.
+#include "SkStackAllocator.h"
+#include "SkTypes.h"
+
+class CountingClass {
+public:
+ CountingClass() {
+ kCount++;
+ }
+
+ ~CountingClass() {
+ kCount--;
+ }
+
+ static int GetCount() { return kCount; }
+
+private:
+ static int kCount;
+};
+
+int CountingClass::kCount;
+
+template<size_t size> void test_allocator(skiatest::Reporter* reporter) {
+ {
+ SkStackAllocator<size> alloc;
+ for (int i = 0; i < 99; ++i) {
+ void* buf = alloc.template reserveT<CountingClass>();
+ SkNEW_PLACEMENT(buf, CountingClass);
+ CountingClass* c = static_cast<CountingClass*>(buf);
+ REPORTER_ASSERT(reporter, c != NULL);
+ REPORTER_ASSERT(reporter, CountingClass::GetCount() == i+1);
+ }
+ }
+ REPORTER_ASSERT(reporter, CountingClass::GetCount() == 0);
+}
+
+DEF_TEST(StackAllocator, reporter) {
+ test_allocator<0>(reporter);
+ test_allocator<5>(reporter);
+ test_allocator<50>(reporter);
+ test_allocator<100>(reporter);
+}
« 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