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

Side by Side Diff: tests/GrUnitTests.cpp

Issue 88113002: Speed up GrResourceCache lookup by inlining GrBinHashKey comparisons (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: address review comments Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "Test.h"
9 #include "TestClassDef.h"
8 10
11 // This is a GPU-backend specific test
12 #if SK_SUPPORT_GPU
9 #include "GrBinHashKey.h" 13 #include "GrBinHashKey.h"
10 #include "GrDrawTarget.h" 14 #include "GrDrawTarget.h"
11 #include "SkMatrix.h" 15 #include "SkMatrix.h"
12 #include "GrRedBlackTree.h" 16 #include "GrRedBlackTree.h"
13 17
14 // FIXME: needs to be in a header
15 void gr_run_unittests();
16
17 // If we aren't inheriting these as #defines from elsewhere, 18 // If we aren't inheriting these as #defines from elsewhere,
18 // clang demands they be declared before we #include the template 19 // clang demands they be declared before we #include the template
19 // that relies on them. 20 // that relies on them.
20 #ifdef SK_DEBUG
21 static bool LT(const int& elem, int value) { 21 static bool LT(const int& elem, int value) {
22 return elem < value; 22 return elem < value;
23 } 23 }
24 static bool EQ(const int& elem, int value) { 24 static bool EQ(const int& elem, int value) {
25 return elem == value; 25 return elem == value;
26 } 26 }
27 #include "GrTBSearch.h" 27 #include "GrTBSearch.h"
28 28
29 static void test_bsearch() { 29
30 DEF_TEST(GrUnitTests_bsearch, reporter) {
30 const int array[] = { 31 const int array[] = {
31 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99 32 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99
32 }; 33 };
33 34
34 for (int n = 0; n < static_cast<int>(GR_ARRAY_COUNT(array)); ++n) { 35 for (int n = 0; n < static_cast<int>(GR_ARRAY_COUNT(array)); ++n) {
35 for (int i = 0; i < n; i++) { 36 for (int i = 0; i < n; i++) {
36 int index = GrTBSearch<int, int>(array, n, array[i]); 37 int index = GrTBSearch<int, int>(array, n, array[i]);
37 SkASSERT(index == (int) i); 38 REPORTER_ASSERT(reporter, index == (int) i);
38 index = GrTBSearch<int, int>(array, n, -array[i]); 39 index = GrTBSearch<int, int>(array, n, -array[i]);
39 SkASSERT(index < 0); 40 REPORTER_ASSERT(reporter, index < 0);
40 } 41 }
41 } 42 }
42 } 43 }
43 #endif
44 44
45 // bogus empty class for GrBinHashKey 45 DEF_TEST(GrUnitTests_binHashKey, reporter) {
46 class BogusEntry {};
47
48 static void test_binHashKey()
49 {
50 const char* testStringA_ = "abcdABCD"; 46 const char* testStringA_ = "abcdABCD";
51 const char* testStringB_ = "abcdBBCD"; 47 const char* testStringB_ = "abcdBBCD";
52 const uint32_t* testStringA = reinterpret_cast<const uint32_t*>(testStringA_ ); 48 const uint32_t* testStringA = reinterpret_cast<const uint32_t*>(testStringA_ );
53 const uint32_t* testStringB = reinterpret_cast<const uint32_t*>(testStringB_ ); 49 const uint32_t* testStringB = reinterpret_cast<const uint32_t*>(testStringB_ );
54 enum { 50 enum {
55 kDataLenUsedForKey = 8 51 kDataLenUsedForKey = 8
56 }; 52 };
57 53
58 GrTBinHashKey<BogusEntry, kDataLenUsedForKey> keyA; 54 GrBinHashKey<kDataLenUsedForKey> keyA;
59 keyA.setKeyData(testStringA); 55 keyA.setKeyData(testStringA);
60 // test copy constructor and comparison 56 // test copy constructor and comparison
61 GrTBinHashKey<BogusEntry, kDataLenUsedForKey> keyA2(keyA); 57 GrBinHashKey<kDataLenUsedForKey> keyA2(keyA);
62 SkASSERT(keyA.compare(keyA2) == 0); 58 REPORTER_ASSERT(reporter, keyA == keyA2);
63 SkASSERT(keyA.getHash() == keyA2.getHash()); 59 REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash());
64 // test re-init 60 // test re-init
65 keyA2.setKeyData(testStringA); 61 keyA2.setKeyData(testStringA);
66 SkASSERT(keyA.compare(keyA2) == 0); 62 REPORTER_ASSERT(reporter, keyA == keyA2);
67 SkASSERT(keyA.getHash() == keyA2.getHash()); 63 REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash());
68 // test sorting 64 // test sorting
69 GrTBinHashKey<BogusEntry, kDataLenUsedForKey> keyB; 65 GrBinHashKey<kDataLenUsedForKey> keyB;
70 keyB.setKeyData(testStringB); 66 keyB.setKeyData(testStringB);
71 SkASSERT(keyA.compare(keyB) < 0); 67 REPORTER_ASSERT(reporter, keyA < keyB);
72 SkASSERT(keyA.getHash() != keyB.getHash()); 68 REPORTER_ASSERT(reporter, keyA.getHash() != keyB.getHash());
73 } 69 }
74 70
75 71
76 void gr_run_unittests() { 72 DEF_TEST(GrUnitTests_redBlackTree, reporter) {
77 SkDEBUGCODE(test_bsearch();)
78 test_binHashKey();
79 GrRedBlackTree<int>::UnitTest(); 73 GrRedBlackTree<int>::UnitTest();
mtklein 2013/11/27 14:36:54 Can you add a little // TODO(mtklein): unwrap this
Kimmo Kinnunen 2013/11/28 07:38:34 Done. (Though this TODO can be fixed also by remov
80 } 74 }
75
76 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698