OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkResourceCache_DEFINED | 8 #ifndef SkResourceCache_DEFINED |
9 #define SkResourceCache_DEFINED | 9 #define SkResourceCache_DEFINED |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 // must call this after your private data has been written. | 33 // must call this after your private data has been written. |
34 // length must be a multiple of 4 | 34 // length must be a multiple of 4 |
35 void init(size_t length); | 35 void init(size_t length); |
36 | 36 |
37 // This is only valid after having called init(). | 37 // This is only valid after having called init(). |
38 uint32_t hash() const { return fHash; } | 38 uint32_t hash() const { return fHash; } |
39 | 39 |
40 bool operator==(const Key& other) const { | 40 bool operator==(const Key& other) const { |
41 const uint32_t* a = this->as32(); | 41 const uint32_t* a = this->as32(); |
42 const uint32_t* b = other.as32(); | 42 const uint32_t* b = other.as32(); |
43 for (int i = 0; i < fCount32; ++i) { | 43 for (int i = 0; i < fCount32; ++i) { // (This checks fCount == othe
r.fCount first.) |
44 if (a[i] != b[i]) { | 44 if (a[i] != b[i]) { |
45 return false; | 45 return false; |
46 } | 46 } |
47 } | 47 } |
48 return true; | 48 return true; |
49 } | 49 } |
50 | 50 |
51 private: | 51 private: |
52 // store fCount32 first, so we don't consider it in operator< | |
53 int32_t fCount32; // 2 + user contents count32 | 52 int32_t fCount32; // 2 + user contents count32 |
54 uint32_t fHash; | 53 uint32_t fHash; |
55 /* uint32_t fContents32[] */ | 54 /* uint32_t fContents32[] */ |
56 | 55 |
57 const uint32_t* as32() const { return (const uint32_t*)this; } | 56 const uint32_t* as32() const { return (const uint32_t*)this; } |
58 const uint32_t* as32SkipCount() const { return this->as32() + 1; } | |
59 }; | 57 }; |
60 | 58 |
61 struct Rec { | 59 struct Rec { |
62 typedef SkResourceCache::Key Key; | 60 typedef SkResourceCache::Key Key; |
63 | 61 |
64 Rec() {} | 62 Rec() {} |
65 virtual ~Rec() {} | 63 virtual ~Rec() {} |
66 | 64 |
67 uint32_t getHash() const { return this->getKey().hash(); } | 65 uint32_t getHash() const { return this->getKey().hash(); } |
68 | 66 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 229 |
232 void init(); // called by constructors | 230 void init(); // called by constructors |
233 | 231 |
234 #ifdef SK_DEBUG | 232 #ifdef SK_DEBUG |
235 void validate() const; | 233 void validate() const; |
236 #else | 234 #else |
237 void validate() const {} | 235 void validate() const {} |
238 #endif | 236 #endif |
239 }; | 237 }; |
240 #endif | 238 #endif |
OLD | NEW |