diff options
author | Brad King <brad.king@kitware.com> | 2014-06-12 15:28:44 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2014-06-12 15:28:44 (GMT) |
commit | bd20dd6b8a925a421167602027fff9b904fd0822 (patch) | |
tree | c6240e2384c8d65310c6568d216a61a33ae50f0f /Source/cmDefinitions.cxx | |
parent | b041fc13db5b3146cd45d8b81b17535ac8747688 (diff) | |
parent | e17a69bc744ce0ed36e41be36694ca0053330d78 (diff) | |
download | CMake-bd20dd6b8a925a421167602027fff9b904fd0822.zip CMake-bd20dd6b8a925a421167602027fff9b904fd0822.tar.gz CMake-bd20dd6b8a925a421167602027fff9b904fd0822.tar.bz2 |
Merge topic 'dev/variable-lookup'
e17a69bc cmDefinitions: Use a hashmap for faster checks
3b21705d cmDefinitions: Avoid a find-then-insert when setting variables
5abfde6c cmDefinitions: Don't store parent lookups
Diffstat (limited to 'Source/cmDefinitions.cxx')
-rw-r--r-- | Source/cmDefinitions.cxx | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx index babf1c4..5515f35 100644 --- a/Source/cmDefinitions.cxx +++ b/Source/cmDefinitions.cxx @@ -15,7 +15,8 @@ cmDefinitions::Def cmDefinitions::NoDef; //---------------------------------------------------------------------------- -cmDefinitions::cmDefinitions(cmDefinitions* parent): Up(parent) +cmDefinitions::cmDefinitions(cmDefinitions* parent) + : Up(parent) { } @@ -28,18 +29,17 @@ void cmDefinitions::Reset(cmDefinitions* parent) //---------------------------------------------------------------------------- cmDefinitions::Def const& -cmDefinitions::GetInternal(const std::string& key) +cmDefinitions::GetInternal(const std::string& key) const { MapType::const_iterator i = this->Map.find(key); if(i != this->Map.end()) { return i->second; } - else if(cmDefinitions* up = this->Up) + if(cmDefinitions* up = this->Up) { - // Query the parent scope and store the result locally. - Def def = up->GetInternal(key); - return this->Map.insert(MapType::value_type(key, def)).first->second; + // Query the parent scope. + return up->GetInternal(key); } return this->NoDef; } @@ -51,16 +51,7 @@ cmDefinitions::SetInternal(const std::string& key, Def const& def) if(this->Up || def.Exists) { // In lower scopes we store keys, defined or not. - MapType::iterator i = this->Map.find(key); - if(i == this->Map.end()) - { - i = this->Map.insert(MapType::value_type(key, def)).first; - } - else - { - i->second = def; - } - return i->second; + return (this->Map[key] = def); } else { @@ -71,13 +62,26 @@ cmDefinitions::SetInternal(const std::string& key, Def const& def) } //---------------------------------------------------------------------------- -const char* cmDefinitions::Get(const std::string& key) +const char* cmDefinitions::Get(const std::string& key) const { Def const& def = this->GetInternal(key); return def.Exists? def.c_str() : 0; } //---------------------------------------------------------------------------- +void cmDefinitions::Pull(const std::string& key) +{ + if (this->Up) + { + Def const& def = this->Up->GetInternal(key); + if (def.Exists) + { + this->SetInternal(key, def); + } + } +} + +//---------------------------------------------------------------------------- const char* cmDefinitions::Set(const std::string& key, const char* value) { Def const& def = this->SetInternal(key, Def(value)); |