summaryrefslogtreecommitdiff
path: root/src/string.hh
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-12-16 18:57:19 +0000
committerMaxime Coste <frrrwww@gmail.com>2014-12-16 18:57:19 +0000
commitebecd60eb810246cfa682a1fbd72270aa9861f0b (patch)
tree0c5c707b68cb08fc93ace2433291deb8a52db5bc /src/string.hh
parentdbd7bd41bbf39d1fd5736997122a4652c78ddc50 (diff)
Rework hashing, use a more extensible framework similar to n3876 proposal
std::hash specialization is a pain to work with, stop using that, and just specialize a 'size_t hash_value(const T&)' free function.
Diffstat (limited to 'src/string.hh')
-rw-r--r--src/string.hh26
1 files changed, 7 insertions, 19 deletions
diff --git a/src/string.hh b/src/string.hh
index eefe6985..afab4486 100644
--- a/src/string.hh
+++ b/src/string.hh
@@ -3,6 +3,7 @@
#include "units.hh"
#include "utf8.hh"
+#include "hash.hh"
#include <string>
#include <climits>
@@ -267,29 +268,16 @@ String expand_tabs(StringView line, CharCount tabstop, CharCount col = 0);
std::vector<StringView> wrap_lines(StringView text, CharCount max_width);
-size_t hash_data(const char* data, size_t len);
-
+inline size_t hash_value(const Kakoune::String& str)
+{
+ return hash_data(str.data(), (int)str.length());
}
-namespace std
+inline size_t hash_value(const Kakoune::StringView& str)
{
- template<>
- struct hash<Kakoune::String> : hash<std::string>
- {
- size_t operator()(const Kakoune::String& str) const
- {
- return hash<std::string>::operator()(str);
- }
- };
+ return hash_data(str.data(), (int)str.length());
+}
- template<>
- struct hash<Kakoune::StringView>
- {
- size_t operator()(Kakoune::StringView str) const
- {
- return Kakoune::hash_data(str.data(), (int)str.length());
- }
- };
}
#endif // string_hh_INCLUDED