| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 } | 45 } |
| 46 | 46 |
| 47 void reset() { | 47 void reset() { |
| 48 fHash = 0; | 48 fHash = 0; |
| 49 #if GR_DEBUG | 49 #if GR_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 GrAssert(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 GR_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 GrAssert(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 |
| 80 static bool EQ(const ENTRY& entry, const GrTBinHashKey<ENTRY, KEY_SIZE>& key
) { | 80 static bool EQ(const ENTRY& entry, const GrTBinHashKey<ENTRY, KEY_SIZE>& key
) { |
| 81 GrAssert(key.fIsValid); | 81 SkASSERT(key.fIsValid); |
| 82 return 0 == entry.compare(key); | 82 return 0 == entry.compare(key); |
| 83 } | 83 } |
| 84 | 84 |
| 85 static bool LT(const ENTRY& entry, const GrTBinHashKey<ENTRY, KEY_SIZE>& key
) { | 85 static bool LT(const ENTRY& entry, const GrTBinHashKey<ENTRY, KEY_SIZE>& key
) { |
| 86 GrAssert(key.fIsValid); | 86 SkASSERT(key.fIsValid); |
| 87 return entry.compare(key) < 0; | 87 return entry.compare(key) < 0; |
| 88 } | 88 } |
| 89 | 89 |
| 90 uint32_t getHash() const { | 90 uint32_t getHash() const { |
| 91 GrAssert(fIsValid); | 91 SkASSERT(fIsValid); |
| 92 return fHash; | 92 return fHash; |
| 93 } | 93 } |
| 94 | 94 |
| 95 const uint8_t* getData() const { | 95 const uint8_t* getData() const { |
| 96 GrAssert(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 GR_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 |