| Index: compiled/StringMap.h |
| =================================================================== |
| --- a/compiled/StringMap.h |
| +++ b/compiled/StringMap.h |
| @@ -17,16 +17,35 @@ |
| #pragma once |
| #include <cstddef> |
| #include "Map.h" |
| #include "String.h" |
| +namespace { |
| + size_t stringHash(const String& key) |
| + { |
| + // FNV-1a hash function |
| + size_t result = 2166136261; |
| + for (size_t i = 0; i < key.length(); i++) |
| + result = (result ^ key[i]) * 16777619; |
| + return result; |
| + } |
| +} |
| + |
| +struct StringHash |
| +{ |
| + size_t operator()(const String& key) const |
| + { |
| + return stringHash(key); |
| + } |
| +}; |
| + |
| namespace StringMap_internal |
| { |
| template<typename Key, |
| class = typename std::enable_if<std::is_base_of<String, Key>::value>::type> |
| struct StringSetEntry |
| { |
| typedef Key key_type; |
| typedef const String& key_type_cref; |
| @@ -57,21 +76,17 @@ |
| void erase() |
| { |
| first.erase(); |
| } |
| static size_type hash(key_type_cref key) |
| { |
| - // FNV-1a hash function |
| - size_type result = 2166136261; |
| - for (String::size_type i = 0; i < key.length(); i++) |
| - result = (result ^ key[i]) * 16777619; |
| - return result; |
| + return stringHash(key); |
| } |
| }; |
| template<typename Key, typename Value> |
| struct StringMapEntry : StringSetEntry<Key> |
| { |
| typedef StringSetEntry<Key> super; |
| typedef Value value_type; |