@@ -98,20 +98,88 @@ using Include = std::variant<std::monostate, SystemInclude, QuoteInclude>;
98
98
99
99
} // namespace
100
100
101
+ template <>
102
+ struct std ::less<Hideset> {
103
+ using is_transparent = void ;
104
+
105
+ bool operator ()(const Hideset &hideset, const Hideset &other) const {
106
+ return hideset.names () < other.names ();
107
+ }
108
+
109
+ bool operator ()(const Hideset &hideset,
110
+ const std::set<std::string_view> &names) const {
111
+ return hideset.names () < names;
112
+ }
113
+
114
+ bool operator ()(const std::set<std::string_view> &names,
115
+ const Hideset &hideset) const {
116
+ return hideset.names () < names;
117
+ }
118
+
119
+ bool operator ()(const Hideset &hideset, const std::string_view &name) const {
120
+ return std::lexicographical_compare (begin (hideset.names ()),
121
+ end (hideset.names ()), &name, &name + 1 );
122
+ }
123
+
124
+ bool operator ()(const std::string_view &name, const Hideset &hideset) const {
125
+ return std::lexicographical_compare (
126
+ &name, &name + 1 , begin (hideset.names ()), end (hideset.names ()));
127
+ }
128
+ };
129
+
101
130
template <>
102
131
struct std ::hash<Hideset> {
132
+ using is_transparent = void ;
133
+
103
134
template <typename T>
104
135
void hash_combine (std::size_t &seed, const T &val) const {
105
136
seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed << 6 ) + (seed >> 2 );
106
137
}
107
138
108
139
std::size_t operator ()(const Hideset &hideset) const {
140
+ return operator ()(hideset.names ());
141
+ }
142
+
143
+ std::size_t operator ()(const std::set<std::string_view> &names) const {
109
144
std::size_t seed = 0 ;
110
- for (const auto &name : hideset.names ()) hash_combine (seed, name);
145
+ for (const auto &name : names) hash_combine (seed, name);
146
+ return seed;
147
+ }
148
+
149
+ std::size_t operator ()(const std::string_view &name) const {
150
+ std::size_t seed = 0 ;
151
+ hash_combine (seed, name);
111
152
return seed;
112
153
}
113
154
};
114
155
156
+ template <>
157
+ struct std ::equal_to<Hideset> {
158
+ using is_transparent = void ;
159
+
160
+ bool operator ()(const Hideset &hideset, const Hideset &other) const {
161
+ return hideset.names () == other.names ();
162
+ }
163
+
164
+ bool operator ()(const Hideset &hideset,
165
+ const std::set<std::string_view> &names) const {
166
+ return hideset.names () == names;
167
+ }
168
+
169
+ bool operator ()(const std::set<std::string_view> &names,
170
+ const Hideset &hideset) const {
171
+ return hideset.names () == names;
172
+ }
173
+
174
+ bool operator ()(const Hideset &hideset, const std::string_view &name) const {
175
+ return hideset.names ().size () == 1 && *hideset.names ().begin () == name;
176
+ }
177
+
178
+ bool operator ()(const std::string_view &name, const Hideset &hideset) const {
179
+ return hideset.names ().size () == 1 && *hideset.names ().begin () == name;
180
+ }
181
+ };
182
+
115
183
namespace cxx {
116
184
117
185
namespace {
@@ -268,7 +336,7 @@ struct Preprocessor::Private {
268
336
std::vector<fs::path> systemIncludePaths_;
269
337
std::vector<fs::path> quoteIncludePaths_;
270
338
std::unordered_map<std::string_view, Macro> macros_;
271
- std::unordered_set <Hideset> hidesets;
339
+ std::set <Hideset> hidesets;
272
340
std::forward_list<std::string> scratchBuffer_;
273
341
std::unordered_set<std::string> pragmaOnceProtected_;
274
342
std::unordered_map<std::string, std::string> ifndefProtectedFiles_;
@@ -353,7 +421,7 @@ struct Preprocessor::Private {
353
421
}
354
422
355
423
const Hideset *makeUnion (const Hideset *hs, const std::string_view &name) {
356
- if (!hs) return get (std::set<std::string_view>{ name} );
424
+ if (!hs) return get (name);
357
425
if (hs->names ().contains (name)) return hs;
358
426
auto names = hs->names ();
359
427
names.insert (name);
@@ -373,9 +441,15 @@ struct Preprocessor::Private {
373
441
return get (std::move (names));
374
442
}
375
443
376
- const Hideset *get (std::set<std::string_view> name) {
377
- if (name.empty ()) return nullptr ;
378
- return &*hidesets.emplace (name).first ;
444
+ const Hideset *get (std::set<std::string_view> names) {
445
+ if (names.empty ()) return nullptr ;
446
+ if (auto it = hidesets.find (names); it != hidesets.end ()) return &*it;
447
+ return &*hidesets.emplace (std::move (names)).first ;
448
+ }
449
+
450
+ const Hideset *get (const std::string_view &name) {
451
+ if (auto it = hidesets.find (name); it != hidesets.end ()) return &*it;
452
+ return &*hidesets.emplace (std::set{name}).first ;
379
453
}
380
454
381
455
std::string readFile (const fs::path &file) const {
0 commit comments