2
2
file Copyright.txt or https://cmake.org/licensing for details. */
3
3
#include " cmDefinitions.h"
4
4
5
+ #include " cm_string_view.hxx"
6
+
5
7
#include < assert.h>
6
- #include < set>
8
+ #include < functional>
9
+ #include < unordered_set>
7
10
#include < utility>
8
11
9
12
cmDefinitions::Def cmDefinitions::NoDef;
@@ -14,7 +17,7 @@ cmDefinitions::Def const& cmDefinitions::GetInternal(const std::string& key,
14
17
{
15
18
assert (begin != end);
16
19
{
17
- MapType::iterator it = begin->Map .find (key);
20
+ auto it = begin->Map .find (key);
18
21
if (it != begin->Map .end ()) {
19
22
it->second .Used = true ;
20
23
return it->second ;
@@ -56,33 +59,10 @@ bool cmDefinitions::HasKey(const std::string& key, StackIter begin,
56
59
return false ;
57
60
}
58
61
59
- void cmDefinitions::Set (const std::string& key, cm::string_view value)
60
- {
61
- this ->Map [key] = Def (value);
62
- }
63
-
64
- void cmDefinitions::Unset (const std::string& key)
65
- {
66
- this ->Map [key] = Def ();
67
- }
68
-
69
- std::vector<std::string> cmDefinitions::UnusedKeys () const
70
- {
71
- std::vector<std::string> keys;
72
- keys.reserve (this ->Map .size ());
73
- // Consider local definitions.
74
- for (auto const & mi : this ->Map ) {
75
- if (!mi.second .Used ) {
76
- keys.push_back (mi.first );
77
- }
78
- }
79
- return keys;
80
- }
81
-
82
62
cmDefinitions cmDefinitions::MakeClosure (StackIter begin, StackIter end)
83
63
{
84
64
cmDefinitions closure;
85
- std::set<std::string > undefined;
65
+ std::unordered_set<cm::string_view > undefined;
86
66
for (StackIter it = begin; it != end; ++it) {
87
67
// Consider local definitions.
88
68
for (auto const & mi : it->Map ) {
@@ -92,7 +72,7 @@ cmDefinitions cmDefinitions::MakeClosure(StackIter begin, StackIter end)
92
72
if (mi.second .Exists ) {
93
73
closure.Map .insert (mi);
94
74
} else {
95
- undefined.insert (mi.first );
75
+ undefined.emplace (mi.first );
96
76
}
97
77
}
98
78
}
@@ -104,17 +84,40 @@ std::vector<std::string> cmDefinitions::ClosureKeys(StackIter begin,
104
84
StackIter end)
105
85
{
106
86
std::vector<std::string> defined;
107
- std::set<std::string > bound;
87
+ std::unordered_set<cm::string_view > bound;
108
88
109
89
for (StackIter it = begin; it != end; ++it) {
110
90
defined.reserve (defined.size () + it->Map .size ());
111
91
for (auto const & mi : it->Map ) {
112
92
// Use this key if it is not already set or unset.
113
- if (bound.insert (mi.first ).second && mi.second .Exists ) {
93
+ if (bound.emplace (mi.first ).second && mi.second .Exists ) {
114
94
defined.push_back (mi.first );
115
95
}
116
96
}
117
97
}
118
98
119
99
return defined;
120
100
}
101
+
102
+ void cmDefinitions::Set (const std::string& key, cm::string_view value)
103
+ {
104
+ this ->Map [key] = Def (value);
105
+ }
106
+
107
+ void cmDefinitions::Unset (const std::string& key)
108
+ {
109
+ this ->Map [key] = Def ();
110
+ }
111
+
112
+ std::vector<std::string> cmDefinitions::UnusedKeys () const
113
+ {
114
+ std::vector<std::string> keys;
115
+ keys.reserve (this ->Map .size ());
116
+ // Consider local definitions.
117
+ for (auto const & mi : this ->Map ) {
118
+ if (!mi.second .Used ) {
119
+ keys.push_back (mi.first );
120
+ }
121
+ }
122
+ return keys;
123
+ }
0 commit comments