Chromium Code Reviews| Index: src/gpu/GrBinHashKey.h |
| diff --git a/src/gpu/GrBinHashKey.h b/src/gpu/GrBinHashKey.h |
| index 7d4aa0fbe8de9af48289a3b32c2cc9574bfafdb0..6dcc58ae4bfde9a3c2cbcb863285b9f16a1d4c33 100644 |
| --- a/src/gpu/GrBinHashKey.h |
| +++ b/src/gpu/GrBinHashKey.h |
| @@ -52,39 +52,59 @@ public: |
| } |
| void setKeyData(const uint32_t* SK_RESTRICT data) { |
| - SkASSERT(GrIsALIGN4(KEY_SIZE)); |
| + SK_COMPILE_ASSERT(KEY_SIZE % sizeof(fData[0]) == 0, key_size_mismatch); |
|
mtklein
2013/11/26 14:20:43
I'd somewhat prefer 4 to sizeof(fData[0]) here.
Kimmo Kinnunen
2013/11/27 08:16:54
Done. Changed the division below to be consistent
|
| memcpy(&fData, data, KEY_SIZE); |
| uint32_t hash = 0; |
| size_t len = KEY_SIZE; |
| while (len >= 4) { |
| hash += *data++; |
| - hash += (fHash << 10); |
| + hash += (hash << 10); |
| hash ^= (hash >> 6); |
| len -= 4; |
| } |
| - hash += (fHash << 3); |
| - hash ^= (fHash >> 11); |
| - hash += (fHash << 15); |
| + hash += (hash << 3); |
| + hash ^= (hash >> 11); |
| + hash += (hash << 15); |
| #ifdef SK_DEBUG |
| fIsValid = true; |
| #endif |
| fHash = hash; |
| } |
| - int compare(const GrTBinHashKey<ENTRY, KEY_SIZE>& key) const { |
| + bool EQ(const GrTBinHashKey<ENTRY, KEY_SIZE>& key) const { |
|
mtklein
2013/11/26 14:20:43
Is the name EQ required by some convention? If no
Kimmo Kinnunen
2013/11/27 08:16:54
Well, not strictly required..
Done.
|
| SkASSERT(fIsValid && key.fIsValid); |
| - return memcmp(fData, key.fData, KEY_SIZE); |
| + if (fHash != key.fHash) { |
| + return false; |
| + } |
| + for (size_t i = 0; i < SK_ARRAY_COUNT(fData); ++i) { |
| + if (fData[i] != key.fData[i]) { |
| + return false; |
| + } |
| + } |
| + return true; |
| + } |
| + |
| + bool LT(const GrTBinHashKey<ENTRY, KEY_SIZE>& key) const { |
|
mtklein
2013/11/26 14:20:43
same here with lessThan
Kimmo Kinnunen
2013/11/27 08:16:54
Done.
|
| + SkASSERT(fIsValid && key.fIsValid); |
| + for (size_t i = 0; i < SK_ARRAY_COUNT(fData); ++i) { |
| + if (fData[i] < key.fData[i]) { |
| + return true; |
| + } else if (fData[i] > key.fData[i]) { |
| + return false; |
| + } |
| + } |
| + return false; |
| } |
| static bool EQ(const ENTRY& entry, const GrTBinHashKey<ENTRY, KEY_SIZE>& key) { |
| SkASSERT(key.fIsValid); |
| - return 0 == entry.compare(key); |
| + return entry.EQ(key); |
| } |
| static bool LT(const ENTRY& entry, const GrTBinHashKey<ENTRY, KEY_SIZE>& key) { |
| SkASSERT(key.fIsValid); |
| - return entry.compare(key) < 0; |
| + return entry.LT(key); |
| } |
| uint32_t getHash() const { |
| @@ -94,12 +114,12 @@ public: |
| const uint8_t* getData() const { |
| SkASSERT(fIsValid); |
| - return fData; |
| + return reinterpret_cast<const uint8_t*>(fData); |
| } |
| private: |
| uint32_t fHash; |
| - uint8_t fData[KEY_SIZE]; // Buffer for key storage |
| + uint32_t fData[KEY_SIZE / sizeof(uint32_t)]; // Buffer for key storage |
| #ifdef SK_DEBUG |
| public: |