Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: compiled/StringMap.h

Issue 29613616: Issue 6064 - Put C++ code into a configurable namespace (Closed) Base URL: https://github.com/adblockplus/adblockpluscore.git
Patch Set: rebase Created Feb. 6, 2018, 9:54 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #pragma once 18 #pragma once
19 19
20 #include <cstddef> 20 #include <cstddef>
21 21
22 #include "base.h"
22 #include "Map.h" 23 #include "Map.h"
23 #include "String.h" 24 #include "String.h"
24 25
25 namespace { 26 ABP_NS_BEGIN
26 size_t stringHash(const String& key) 27 namespace StringMap_internal
sergei 2018/02/06 10:03:17 here is actually an unrelated change, we are norma
28 {
29 inline size_t stringHash(const String& key)
27 { 30 {
28 // FNV-1a hash function 31 // FNV-1a hash function
29 size_t result = 2166136261; 32 size_t result = 2166136261;
30 for (size_t i = 0; i < key.length(); i++) 33 for (size_t i = 0; i < key.length(); i++)
31 result = (result ^ key[i]) * 16777619; 34 result = (result ^ key[i]) * 16777619;
32 return result; 35 return result;
33 } 36 }
34 } 37 }
35 38
36 struct StringHash 39 struct StringHash
37 { 40 {
38 size_t operator()(const String& key) const 41 size_t operator()(const String& key) const
39 { 42 {
40 return stringHash(key); 43 return StringMap_internal::stringHash(key);
41 } 44 }
42 }; 45 };
43 46
44 namespace StringMap_internal 47 namespace StringMap_internal
45 { 48 {
46 template<typename Key, 49 template<typename Key,
47 class = typename std::enable_if<std::is_base_of<String, Key>::value>::type> 50 class = typename std::enable_if<std::is_base_of<String, Key>::value>::type>
48 struct StringSetEntry 51 struct StringSetEntry
49 { 52 {
50 typedef Key key_type; 53 typedef Key key_type;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 109 }
107 }; 110 };
108 } 111 }
109 112
110 using StringSet = Set<StringMap_internal::StringSetEntry<DependentString>>; 113 using StringSet = Set<StringMap_internal::StringSetEntry<DependentString>>;
111 114
112 template<typename Value> 115 template<typename Value>
113 using StringMap = Map<StringMap_internal::StringMapEntry<DependentString, Value> >; 116 using StringMap = Map<StringMap_internal::StringMapEntry<DependentString, Value> >;
114 template<typename Value> 117 template<typename Value>
115 using OwnedStringMap = Map<StringMap_internal::StringMapEntry<OwnedString, Value >>; 118 using OwnedStringMap = Map<StringMap_internal::StringMapEntry<OwnedString, Value >>;
119 ABP_NS_END
OLDNEW
« no previous file with comments | « compiled/String.h ('k') | compiled/StringScanner.h » ('j') | compiled/base.h » ('J')

Powered by Google App Engine
This is Rietveld