diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2014-12-16 18:57:19 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2014-12-16 18:57:19 +0000 |
| commit | ebecd60eb810246cfa682a1fbd72270aa9861f0b (patch) | |
| tree | 0c5c707b68cb08fc93ace2433291deb8a52db5bc /src/interned_string.hh | |
| parent | dbd7bd41bbf39d1fd5736997122a4652c78ddc50 (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/interned_string.hh')
| -rw-r--r-- | src/interned_string.hh | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/src/interned_string.hh b/src/interned_string.hh index fd79de2c..41a1b034 100644 --- a/src/interned_string.hh +++ b/src/interned_string.hh @@ -3,8 +3,7 @@ #include "string.hh" #include "utils.hh" - -#include <unordered_map> +#include "unordered_map.hh" namespace Kakoune { @@ -20,7 +19,7 @@ private: void acquire(size_t slot); void release(size_t slot) noexcept; - std::unordered_map<StringView, size_t> m_slot_map; + UnorderedMap<StringView, size_t> m_slot_map; std::vector<size_t> m_free_slots; using DataAndRefCount = std::pair<std::vector<char>, int>; std::vector<DataAndRefCount> m_storage; @@ -118,18 +117,11 @@ private: size_t m_slot = -1; }; +inline size_t hash_value(const Kakoune::InternedString& str) +{ + return hash_data(str.data(), (int)str.length()); } -namespace std -{ - template<> - struct hash<Kakoune::InternedString> - { - size_t operator()(const Kakoune::InternedString& str) const - { - return Kakoune::hash_data(str.data(), (int)str.length()); - } - }; } #endif // interned_string_hh_INCLUDED |
