OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 | 8 |
9 | 9 |
10 #ifndef GrBinHashKey_DEFINED | 10 #ifndef GrBinHashKey_DEFINED |
(...skipping 28 matching lines...) Expand all Loading... |
39 GrTBinHashKey<ENTRY, KEY_SIZE>& operator=(const GrTBinHashKey<ENTRY, KEY_SIZ
E>& other) { | 39 GrTBinHashKey<ENTRY, KEY_SIZE>& operator=(const GrTBinHashKey<ENTRY, KEY_SIZ
E>& other) { |
40 memcpy(this, &other, sizeof(*this)); | 40 memcpy(this, &other, sizeof(*this)); |
41 return *this; | 41 return *this; |
42 } | 42 } |
43 | 43 |
44 ~GrTBinHashKey() { | 44 ~GrTBinHashKey() { |
45 } | 45 } |
46 | 46 |
47 void reset() { | 47 void reset() { |
48 fHash = 0; | 48 fHash = 0; |
49 #if GR_DEBUG | 49 #if SK_DEBUG |
50 fIsValid = false; | 50 fIsValid = false; |
51 #endif | 51 #endif |
52 } | 52 } |
53 | 53 |
54 void setKeyData(const uint32_t* SK_RESTRICT data) { | 54 void setKeyData(const uint32_t* SK_RESTRICT data) { |
55 SkASSERT(GrIsALIGN4(KEY_SIZE)); | 55 SkASSERT(GrIsALIGN4(KEY_SIZE)); |
56 memcpy(&fData, data, KEY_SIZE); | 56 memcpy(&fData, data, KEY_SIZE); |
57 | 57 |
58 uint32_t hash = 0; | 58 uint32_t hash = 0; |
59 size_t len = KEY_SIZE; | 59 size_t len = KEY_SIZE; |
60 while (len >= 4) { | 60 while (len >= 4) { |
61 hash += *data++; | 61 hash += *data++; |
62 hash += (fHash << 10); | 62 hash += (fHash << 10); |
63 hash ^= (hash >> 6); | 63 hash ^= (hash >> 6); |
64 len -= 4; | 64 len -= 4; |
65 } | 65 } |
66 hash += (fHash << 3); | 66 hash += (fHash << 3); |
67 hash ^= (fHash >> 11); | 67 hash ^= (fHash >> 11); |
68 hash += (fHash << 15); | 68 hash += (fHash << 15); |
69 #if GR_DEBUG | 69 #if SK_DEBUG |
70 fIsValid = true; | 70 fIsValid = true; |
71 #endif | 71 #endif |
72 fHash = hash; | 72 fHash = hash; |
73 } | 73 } |
74 | 74 |
75 int compare(const GrTBinHashKey<ENTRY, KEY_SIZE>& key) const { | 75 int compare(const GrTBinHashKey<ENTRY, KEY_SIZE>& key) const { |
76 SkASSERT(fIsValid && key.fIsValid); | 76 SkASSERT(fIsValid && key.fIsValid); |
77 return memcmp(fData, key.fData, KEY_SIZE); | 77 return memcmp(fData, key.fData, KEY_SIZE); |
78 } | 78 } |
79 | 79 |
(...skipping 14 matching lines...) Expand all Loading... |
94 | 94 |
95 const uint8_t* getData() const { | 95 const uint8_t* getData() const { |
96 SkASSERT(fIsValid); | 96 SkASSERT(fIsValid); |
97 return fData; | 97 return fData; |
98 } | 98 } |
99 | 99 |
100 private: | 100 private: |
101 uint32_t fHash; | 101 uint32_t fHash; |
102 uint8_t fData[KEY_SIZE]; // Buffer for key storage | 102 uint8_t fData[KEY_SIZE]; // Buffer for key storage |
103 | 103 |
104 #if GR_DEBUG | 104 #if SK_DEBUG |
105 public: | 105 public: |
106 bool fIsValid; | 106 bool fIsValid; |
107 #endif | 107 #endif |
108 }; | 108 }; |
109 | 109 |
110 #endif | 110 #endif |
OLD | NEW |