summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2014-03-12 18:01:45 (GMT)
committerBen Boeckel <ben.boeckel@kitware.com>2014-06-09 18:46:45 (GMT)
commit5abfde6cb8a1ae0b2825797eab6c2e9842eb7c49 (patch)
tree9d9b686577045406f0afdc5af93acb523929c1eb /Source
parent9e8fa1043ce9bfcffdcfa395f618dd7958ef4251 (diff)
downloadCMake-5abfde6cb8a1ae0b2825797eab6c2e9842eb7c49.zip
CMake-5abfde6cb8a1ae0b2825797eab6c2e9842eb7c49.tar.gz
CMake-5abfde6cb8a1ae0b2825797eab6c2e9842eb7c49.tar.bz2
cmDefinitions: Don't store parent lookups
When looking up scopes, it is faster to not store the lookup locally to keep the maps smaller and avoid extra allocations and rebalancing.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmDefinitions.cxx22
-rw-r--r--Source/cmDefinitions.h10
-rw-r--r--Source/cmMakefile.cxx2
3 files changed, 24 insertions, 10 deletions
diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index babf1c4..98becf8 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -28,7 +28,7 @@ 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())
@@ -37,9 +37,8 @@ cmDefinitions::GetInternal(const std::string& key)
}
else 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;
}
@@ -71,13 +70,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));
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index d615fb0..ebe6fa5 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -33,9 +33,11 @@ public:
/** Returns the parent scope, if any. */
cmDefinitions* GetParent() const { return this->Up; }
- /** Get the value associated with a key; null if none.
- Store the result locally if it came from a parent. */
- const char* Get(const std::string& key);
+ /** Get the value associated with a key; null if none. */
+ const char* Get(const std::string& key) const;
+
+ /** Pull a variable from the parent. */
+ void Pull(const std::string& key);
/** Set (or unset if null) a value associated with a key. */
const char* Set(const std::string& key, const char* value);
@@ -73,7 +75,7 @@ private:
MapType Map;
// Internal query and update methods.
- Def const& GetInternal(const std::string& key);
+ Def const& GetInternal(const std::string& key) const;
Def const& SetInternal(const std::string& key, Def const& def);
// Implementation of Closure() method.
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 630957f..412c998 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -4422,7 +4422,7 @@ void cmMakefile::RaiseScope(const std::string& var, const char *varDef)
if(cmDefinitions* up = cur.GetParent())
{
// First localize the definition in the current scope.
- cur.Get(var);
+ cur.Pull(var);
// Now update the definition in the parent scope.
up->Set(var, varDef);