summaryrefslogtreecommitdiffstats
path: root/Source/cmDefinitions.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-08-08 18:50:09 (GMT)
committerBrad King <brad.king@kitware.com>2019-08-20 13:36:45 (GMT)
commitbe7807478c463c5c875798a3e2e72e148c0d0c3e (patch)
tree05152d75d6aa1d520c6e6da48732d095037f002d /Source/cmDefinitions.cxx
parente07e2bc8bbf25178270e8086575ff398dd1fa0c6 (diff)
downloadCMake-be7807478c463c5c875798a3e2e72e148c0d0c3e.zip
CMake-be7807478c463c5c875798a3e2e72e148c0d0c3e.tar.gz
CMake-be7807478c463c5c875798a3e2e72e148c0d0c3e.tar.bz2
cmDefinitions: Reduce allocation of keys and values in MakeClosure
Use `cm::String` to store keys and values so that `MakeClosure` does not need to allocate new copies of all of them. Issue: #19581
Diffstat (limited to 'Source/cmDefinitions.cxx')
-rw-r--r--Source/cmDefinitions.cxx18
1 files changed, 9 insertions, 9 deletions
diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index cc38d84..e688890 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -17,7 +17,7 @@ cmDefinitions::Def const& cmDefinitions::GetInternal(const std::string& key,
{
assert(begin != end);
{
- auto it = begin->Map.find(key);
+ auto it = begin->Map.find(cm::String::borrow(key));
if (it != begin->Map.end()) {
it->second.Used = true;
return it->second;
@@ -39,7 +39,7 @@ const std::string* cmDefinitions::Get(const std::string& key, StackIter begin,
StackIter end)
{
Def const& def = cmDefinitions::GetInternal(key, begin, end, false);
- return def.Exists ? &def.Value : nullptr;
+ return def.Value ? def.Value.str_if_stable() : nullptr;
}
void cmDefinitions::Raise(const std::string& key, StackIter begin,
@@ -52,7 +52,7 @@ bool cmDefinitions::HasKey(const std::string& key, StackIter begin,
StackIter end)
{
for (StackIter it = begin; it != end; ++it) {
- if (it->Map.find(key) != it->Map.end()) {
+ if (it->Map.find(cm::String::borrow(key)) != it->Map.end()) {
return true;
}
}
@@ -68,11 +68,11 @@ cmDefinitions cmDefinitions::MakeClosure(StackIter begin, StackIter end)
for (auto const& mi : it->Map) {
// Use this key if it is not already set or unset.
if (closure.Map.find(mi.first) == closure.Map.end() &&
- undefined.find(mi.first) == undefined.end()) {
- if (mi.second.Exists) {
+ undefined.find(mi.first.view()) == undefined.end()) {
+ if (mi.second.Value) {
closure.Map.insert(mi);
} else {
- undefined.emplace(mi.first);
+ undefined.emplace(mi.first.view());
}
}
}
@@ -90,8 +90,8 @@ std::vector<std::string> cmDefinitions::ClosureKeys(StackIter begin,
defined.reserve(defined.size() + it->Map.size());
for (auto const& mi : it->Map) {
// Use this key if it is not already set or unset.
- if (bound.emplace(mi.first).second && mi.second.Exists) {
- defined.push_back(mi.first);
+ if (bound.emplace(mi.first.view()).second && mi.second.Value) {
+ defined.push_back(*mi.first.str_if_stable());
}
}
}
@@ -116,7 +116,7 @@ std::vector<std::string> cmDefinitions::UnusedKeys() const
// Consider local definitions.
for (auto const& mi : this->Map) {
if (!mi.second.Used) {
- keys.push_back(mi.first);
+ keys.push_back(*mi.first.str_if_stable());
}
}
return keys;