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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dm/DM.cpp ('k') | include/private/SkTHash.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/private/SkChecksum.h
diff --git a/include/private/SkChecksum.h b/include/private/SkChecksum.h
index 8eb1766ec0c2639b23b3a7e29cac9b291d3340c4..cbc8a73a3e59e215aee0818fa3fb9f3da009f6ae 100644
--- a/include/private/SkChecksum.h
+++ b/include/private/SkChecksum.h
@@ -182,17 +182,20 @@ public:
// SkGoodHash should usually be your first choice in hashing data.
// It should be both reasonably fast and high quality.
-
-template <typename K>
-uint32_t SkGoodHash(const K& k) {
- if (sizeof(K) == 4) {
+struct SkGoodHash {
+ template <typename K>
+ SK_WHEN(sizeof(K) == 4, uint32_t) operator()(const K& k) const {
return SkChecksum::Mix(*(const uint32_t*)&k);
}
- return SkChecksum::Murmur3(&k, sizeof(K));
-}
-inline uint32_t SkGoodHash(const SkString& k) {
- return SkChecksum::Murmur3(k.c_str(), k.size());
-}
+ template <typename K>
+ SK_WHEN(sizeof(K) != 4, uint32_t) operator()(const K& k) const {
+ return SkChecksum::Murmur3(&k, sizeof(K));
+ }
+
+ uint32_t operator()(const SkString& k) const {
+ return SkChecksum::Murmur3(k.c_str(), k.size());
+ }
+};
#endif
« 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