diff options
author | Jacques Lucke <jacques@blender.org> | 2020-04-25 00:14:33 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-04-25 00:14:33 +0300 |
commit | ebe0d7ca5e7a10188308f1a9882e2d663ba1cef5 (patch) | |
tree | 95902b90d82aa058907922027db941f9bce17fcc /source/blender/blenlib/BLI_hash.hh | |
parent | 62f6255b476a9fbd2c85b8fc7466734da912fa34 (diff) |
BLI: add DefaultHash specializations for StringRef and StringRefNull
Diffstat (limited to 'source/blender/blenlib/BLI_hash.hh')
-rw-r--r-- | source/blender/blenlib/BLI_hash.hh | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/source/blender/blenlib/BLI_hash.hh b/source/blender/blenlib/BLI_hash.hh index b5041012189..3b3448f66b1 100644 --- a/source/blender/blenlib/BLI_hash.hh +++ b/source/blender/blenlib/BLI_hash.hh @@ -30,6 +30,7 @@ #include <utility> #include "BLI_math_base.h" +#include "BLI_string_ref.hh" #include "BLI_utildefines.h" namespace BLI { @@ -67,14 +68,33 @@ template<> struct DefaultHash<float> { } }; +inline uint32_t hash_string(StringRef str) +{ + uint32_t hash = 5381; + for (char c : str) { + hash = hash * 33 + c; + } + return hash; +} + template<> struct DefaultHash<std::string> { uint32_t operator()(const std::string &value) const { - uint32_t hash = 5381; - for (char c : value) { - hash = hash * 33 + c; - } - return hash; + return hash_string(value); + } +}; + +template<> struct DefaultHash<StringRef> { + uint32_t operator()(const StringRef &value) const + { + return hash_string(value); + } +}; + +template<> struct DefaultHash<StringRefNull> { + uint32_t operator()(const StringRefNull &value) const + { + return hash_string(value); } }; |