Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: include/private/SkChecksum.h

Issue 1405053002: SkTHash: hash from fnptr to functor type (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « dm/DM.cpp ('k') | include/private/SkTHash.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « dm/DM.cpp ('k') | include/private/SkTHash.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698