| Index: compiled/StringMap.h |
| =================================================================== |
| --- a/compiled/StringMap.h |
| +++ b/compiled/StringMap.h |
| @@ -13,25 +13,47 @@ |
| * |
| * You should have received a copy of the GNU General Public License |
| * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| */ |
| #pragma once |
| #include <cstddef> |
| +#include <type_traits> |
| #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 DependentString key_type; |
| + typedef Key key_type; |
| typedef const String& key_type_cref; |
| typedef size_t size_type; |
| key_type first; |
| StringSetEntry(key_type_cref key = key_type()) |
| { |
| if (!key.is_invalid()) |
| @@ -55,42 +77,40 @@ |
| 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 Value> |
| - struct StringMapEntry : StringSetEntry |
| + template<typename Key, typename Value> |
| + struct StringMapEntry : StringSetEntry<Key> |
| { |
| - typedef StringSetEntry super; |
| + typedef StringSetEntry<Key> super; |
| typedef Value value_type; |
| value_type second; |
| - StringMapEntry(key_type_cref key = DependentString(), |
| + StringMapEntry(typename super::key_type_cref key = Key(), |
| value_type value = value_type()) |
| : super(key), second(value) |
| { |
| } |
| void erase() |
| { |
| super::erase(); |
| second = value_type(); |
| } |
| }; |
| } |
| -using StringSet = Set<StringMap_internal::StringSetEntry>; |
| +using StringSet = Set<StringMap_internal::StringSetEntry<DependentString>>; |
| template<typename Value> |
| -using StringMap = Map<StringMap_internal::StringMapEntry<Value>>; |
| +using StringMap = Map<StringMap_internal::StringMapEntry<DependentString, Value>>; |
| +template<typename Value> |
| +using OwnedStringMap = Map<StringMap_internal::StringMapEntry<OwnedString, Value>>; |