diff options
author | 2015-10-15 12:23:01 -0700 | |
---|---|---|
committer | 2015-10-15 12:23:02 -0700 | |
commit | c8d1dd48c01f562cfffe64da0e5cee5ed2713541 (patch) | |
tree | d561462e44e5b2f644b41c1fd670c1e66c5f03de /include/private/SkChecksum.h | |
parent | b9519f86bbce946e505980a4fa950fdc4bcf74ab (diff) |
SkTHash: hash from fnptr to functor type
Passing &SkGoodHash to SkTHashMap and SkTHashSet doesn't guarantee that it's actually instantiated. Using a functor does.
BUG=skia:
Review URL: https://codereview.chromium.org/1405053002
Diffstat (limited to 'include/private/SkChecksum.h')
-rw-r--r-- | include/private/SkChecksum.h | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/include/private/SkChecksum.h b/include/private/SkChecksum.h index 8eb1766ec0..cbc8a73a3e 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 |