[Bf-blender-cvs] [ebe0d7ca5e7] master: BLI: add DefaultHash specializations for StringRef and StringRefNull
Jacques Lucke
noreply at git.blender.org
Fri Apr 24 23:14:45 CEST 2020
Commit: ebe0d7ca5e7a10188308f1a9882e2d663ba1cef5
Author: Jacques Lucke
Date: Fri Apr 24 23:14:33 2020 +0200
Branches: master
https://developer.blender.org/rBebe0d7ca5e7a10188308f1a9882e2d663ba1cef5
BLI: add DefaultHash specializations for StringRef and StringRefNull
===================================================================
M source/blender/blenlib/BLI_hash.hh
===================================================================
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);
}
};
More information about the Bf-blender-cvs
mailing list