cmDefinitions: Externalize looping for ClosureKeys.

This commit is contained in:
Stephen Kelly 2015-04-26 15:38:36 +02:00
parent f79cd99d6d
commit 5ccff6408c
3 changed files with 20 additions and 18 deletions

View File

@ -116,26 +116,19 @@ cmDefinitions::MakeClosure(std::set<std::string>& undefined,
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::vector<std::string> cmDefinitions::ClosureKeys() const std::vector<std::string>
cmDefinitions::ClosureKeys(std::set<std::string>& bound) const
{ {
std::vector<std::string> defined; std::vector<std::string> defined;
std::set<std::string> bound; defined.reserve(this->Map.size());
for(MapType::const_iterator mi = this->Map.begin();
cmDefinitions const* up = this; mi != this->Map.end(); ++mi)
while (up)
{ {
// Consider local definitions. // Use this key if it is not already set or unset.
for(MapType::const_iterator mi = up->Map.begin(); if(bound.insert(mi->first).second && mi->second.Exists)
mi != up->Map.end(); ++mi)
{ {
// Use this key if it is not already set or unset. defined.push_back(mi->first);
if(bound.insert(mi->first).second && mi->second.Exists)
{
defined.push_back(mi->first);
}
} }
up = up->Up;
} }
return defined; return defined;
} }

View File

@ -47,8 +47,8 @@ public:
/** Get the set of all local keys. */ /** Get the set of all local keys. */
std::vector<std::string> LocalKeys() const; std::vector<std::string> LocalKeys() const;
/** Compute the set of all defined keys. */ std::vector<std::string>
std::vector<std::string> ClosureKeys() const; ClosureKeys(std::set<std::string>& bound) const;
static cmDefinitions MakeClosure( static cmDefinitions MakeClosure(
std::list<cmDefinitions>::const_reverse_iterator rbegin, std::list<cmDefinitions>::const_reverse_iterator rbegin,

View File

@ -98,7 +98,16 @@ public:
std::vector<std::string> ClosureKeys() const std::vector<std::string> ClosureKeys() const
{ {
return this->VarStack.back().ClosureKeys(); std::vector<std::string> closureKeys;
std::set<std::string> bound;
for (std::list<cmDefinitions>::const_reverse_iterator it =
this->VarStack.rbegin(); it != this->VarStack.rend(); ++it)
{
std::vector<std::string> const& localKeys = it->ClosureKeys(bound);
closureKeys.insert(closureKeys.end(),
localKeys.begin(), localKeys.end());
}
return closureKeys;
} }
void PopDefinitions() void PopDefinitions()