From 5ccff6408c93e67d7f8445ce1bf6465b068d6f6b Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 26 Apr 2015 15:38:36 +0200 Subject: cmDefinitions: Externalize looping for ClosureKeys. --- Source/cmDefinitions.cxx | 23 ++++++++--------------- Source/cmDefinitions.h | 4 ++-- Source/cmMakefile.cxx | 11 ++++++++++- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx index 718d9ec..115e30a 100644 --- a/Source/cmDefinitions.cxx +++ b/Source/cmDefinitions.cxx @@ -116,26 +116,19 @@ cmDefinitions::MakeClosure(std::set& undefined, } //---------------------------------------------------------------------------- -std::vector cmDefinitions::ClosureKeys() const +std::vector +cmDefinitions::ClosureKeys(std::set& bound) const { std::vector defined; - std::set bound; - - cmDefinitions const* up = this; - - while (up) + defined.reserve(this->Map.size()); + for(MapType::const_iterator mi = this->Map.begin(); + mi != this->Map.end(); ++mi) { - // Consider local definitions. - for(MapType::const_iterator mi = up->Map.begin(); - mi != up->Map.end(); ++mi) + // Use this key if it is not already set or unset. + if(bound.insert(mi->first).second && mi->second.Exists) { - // Use this key if it is not already set or unset. - if(bound.insert(mi->first).second && mi->second.Exists) - { - defined.push_back(mi->first); - } + defined.push_back(mi->first); } - up = up->Up; } return defined; } diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h index 87f5c34..4c7f11f 100644 --- a/Source/cmDefinitions.h +++ b/Source/cmDefinitions.h @@ -47,8 +47,8 @@ public: /** Get the set of all local keys. */ std::vector LocalKeys() const; - /** Compute the set of all defined keys. */ - std::vector ClosureKeys() const; + std::vector + ClosureKeys(std::set& bound) const; static cmDefinitions MakeClosure( std::list::const_reverse_iterator rbegin, diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 6451874..1d3e496 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -98,7 +98,16 @@ public: std::vector ClosureKeys() const { - return this->VarStack.back().ClosureKeys(); + std::vector closureKeys; + std::set bound; + for (std::list::const_reverse_iterator it = + this->VarStack.rbegin(); it != this->VarStack.rend(); ++it) + { + std::vector const& localKeys = it->ClosureKeys(bound); + closureKeys.insert(closureKeys.end(), + localKeys.begin(), localKeys.end()); + } + return closureKeys; } void PopDefinitions() -- cgit v0.12