OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 SkChecksum_DEFINED | 8 #ifndef SkChecksum_DEFINED |
9 #define SkChecksum_DEFINED | 9 #define SkChecksum_DEFINED |
10 | 10 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 */ | 175 */ |
176 if (8 == sizeof(result)) { | 176 if (8 == sizeof(result)) { |
177 result ^= result >> HALFBITS; | 177 result ^= result >> HALFBITS; |
178 } | 178 } |
179 return static_cast<uint32_t>(result); | 179 return static_cast<uint32_t>(result); |
180 } | 180 } |
181 }; | 181 }; |
182 | 182 |
183 // SkGoodHash should usually be your first choice in hashing data. | 183 // SkGoodHash should usually be your first choice in hashing data. |
184 // It should be both reasonably fast and high quality. | 184 // It should be both reasonably fast and high quality. |
185 | 185 struct SkGoodHash { |
186 template <typename K> | 186 template <typename K> |
187 uint32_t SkGoodHash(const K& k) { | 187 SK_WHEN(sizeof(K) == 4, uint32_t) operator()(const K& k) const { |
188 if (sizeof(K) == 4) { | |
189 return SkChecksum::Mix(*(const uint32_t*)&k); | 188 return SkChecksum::Mix(*(const uint32_t*)&k); |
190 } | 189 } |
191 return SkChecksum::Murmur3(&k, sizeof(K)); | |
192 } | |
193 | 190 |
194 inline uint32_t SkGoodHash(const SkString& k) { | 191 template <typename K> |
195 return SkChecksum::Murmur3(k.c_str(), k.size()); | 192 SK_WHEN(sizeof(K) != 4, uint32_t) operator()(const K& k) const { |
196 } | 193 return SkChecksum::Murmur3(&k, sizeof(K)); |
| 194 } |
| 195 |
| 196 uint32_t operator()(const SkString& k) const { |
| 197 return SkChecksum::Murmur3(k.c_str(), k.size()); |
| 198 } |
| 199 }; |
197 | 200 |
198 #endif | 201 #endif |
OLD | NEW |