diff options
author | 2017-03-15 20:52:35 -0400 | |
---|---|---|
committer | 2017-03-16 13:08:04 +0000 | |
commit | 69225d02500c882053864410b1b775197455f2c5 (patch) | |
tree | 46ffa2c1056efee1968a01b492571a1856eff1d8 /tests | |
parent | 0c984a0af30989fe20b1f8af18867983a88c48b6 (diff) |
Make SkTArray not allocate unless reserve or initial count > 0
This also makes it so that it doesn't shrink back into preallocated storage and therefore doesn't need to store the reserve count.
Change-Id: Ia320fed04c329641a5494947db39cefd2fb6d80f
Reviewed-on: https://skia-review.googlesource.com/9531
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/TArrayTest.cpp | 68 |
1 files changed, 66 insertions, 2 deletions
diff --git a/tests/TArrayTest.cpp b/tests/TArrayTest.cpp index d1331b58a8..6e23c49b35 100644 --- a/tests/TArrayTest.cpp +++ b/tests/TArrayTest.cpp @@ -11,9 +11,9 @@ // Tests the SkTArray<T> class template. -template <bool MEM_COPY> +template <bool MEM_MOVE> static void TestTSet_basic(skiatest::Reporter* reporter) { - SkTArray<int, MEM_COPY> a; + SkTArray<int, MEM_MOVE> a; // Starts empty. REPORTER_ASSERT(reporter, a.empty()); @@ -219,6 +219,68 @@ static void test_move(skiatest::Reporter* reporter) { #undef TEST_MOVE } +template <typename T, bool MEM_MOVE> int SkTArray<T, MEM_MOVE>::allocCntForTest() const { + return fAllocCount; +} + +void test_unnecessary_alloc(skiatest::Reporter* reporter) { + { + SkTArray<int> a; + REPORTER_ASSERT(reporter, a.allocCntForTest() == 0); + } + { + SkSTArray<10, int> a; + REPORTER_ASSERT(reporter, a.allocCntForTest() == 10); + } + { + SkTArray<int> a(1); + REPORTER_ASSERT(reporter, a.allocCntForTest() >= 1); + } + { + SkTArray<int> a, b; + b = a; + REPORTER_ASSERT(reporter, b.allocCntForTest() == 0); + } + { + SkSTArray<10, int> a; + SkTArray<int> b; + b = a; + REPORTER_ASSERT(reporter, b.allocCntForTest() == 0); + } + { + SkTArray<int> a; + SkTArray<int> b(a); + REPORTER_ASSERT(reporter, b.allocCntForTest() == 0); + } + { + SkSTArray<10, int> a; + SkTArray<int> b(a); + REPORTER_ASSERT(reporter, b.allocCntForTest() == 0); + } + { + SkTArray<int> a; + SkTArray<int> b(std::move(a)); + REPORTER_ASSERT(reporter, b.allocCntForTest() == 0); + } + { + SkSTArray<10, int> a; + SkTArray<int> b(std::move(a)); + REPORTER_ASSERT(reporter, b.allocCntForTest() == 0); + } + { + SkTArray<int> a; + SkTArray<int> b; + b = std::move(a); + REPORTER_ASSERT(reporter, b.allocCntForTest() == 0); + } + { + SkSTArray<10, int> a; + SkTArray<int> b; + b = std::move(a); + REPORTER_ASSERT(reporter, b.allocCntForTest() == 0); + } +} + DEF_TEST(TArray, reporter) { TestTSet_basic<true>(reporter); TestTSet_basic<false>(reporter); @@ -232,4 +294,6 @@ DEF_TEST(TArray, reporter) { test_copy_ctor(reporter, SkSTArray<10, sk_sp<SkRefCnt>, true>()); test_move(reporter); + + test_unnecessary_alloc(reporter); } |