cmMakefile: Raise variable in scope explicitly when needed.

The Get method implicitly pulls a copy of all variables into a local scope. This
is not necessary.
This commit is contained in:
Stephen Kelly 2015-05-17 13:21:02 +02:00
parent c8cb66880c
commit ea7b962be2
3 changed files with 17 additions and 7 deletions

View File

@ -18,7 +18,7 @@ cmDefinitions::Def cmDefinitions::NoDef;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmDefinitions::Def const& cmDefinitions::GetInternal( cmDefinitions::Def const& cmDefinitions::GetInternal(
const std::string& key, StackIter begin, StackIter end) const std::string& key, StackIter begin, StackIter end, bool raise)
{ {
assert(begin != end); assert(begin != end);
MapType::const_iterator i = begin->Map.find(key); MapType::const_iterator i = begin->Map.find(key);
@ -32,7 +32,11 @@ cmDefinitions::Def const& cmDefinitions::GetInternal(
{ {
return cmDefinitions::NoDef; return cmDefinitions::NoDef;
} }
Def const& def = cmDefinitions::GetInternal(key, it, end); Def const& def = cmDefinitions::GetInternal(key, it, end, raise);
if (!raise)
{
return def;
}
return begin->Map.insert(MapType::value_type(key, def)).first->second; return begin->Map.insert(MapType::value_type(key, def)).first->second;
} }
@ -40,10 +44,16 @@ cmDefinitions::Def const& cmDefinitions::GetInternal(
const char* cmDefinitions::Get(const std::string& key, const char* cmDefinitions::Get(const std::string& key,
StackIter begin, StackIter end) StackIter begin, StackIter end)
{ {
Def const& def = cmDefinitions::GetInternal(key, begin, end); Def const& def = cmDefinitions::GetInternal(key, begin, end, false);
return def.Exists? def.c_str() : 0; return def.Exists? def.c_str() : 0;
} }
void cmDefinitions::Raise(const std::string& key,
StackIter begin, StackIter end)
{
cmDefinitions::GetInternal(key, begin, end, true);
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmDefinitions::Set(const std::string& key, const char* value) void cmDefinitions::Set(const std::string& key, const char* value)
{ {

View File

@ -35,11 +35,11 @@ class cmDefinitions
typedef std::list<cmDefinitions>::reverse_iterator StackIter; typedef std::list<cmDefinitions>::reverse_iterator StackIter;
typedef std::list<cmDefinitions>::const_reverse_iterator StackConstIter; typedef std::list<cmDefinitions>::const_reverse_iterator StackConstIter;
public: public:
/** Get the value associated with a key; null if none.
Store the result locally if it came from a parent. */
static const char* Get(const std::string& key, static const char* Get(const std::string& key,
StackIter begin, StackIter end); StackIter begin, StackIter end);
static void Raise(const std::string& key, StackIter begin, StackIter end);
/** Set (or unset if null) a value associated with a key. */ /** Set (or unset if null) a value associated with a key. */
void Set(const std::string& key, const char* value); void Set(const std::string& key, const char* value);
@ -80,7 +80,7 @@ private:
MapType Map; MapType Map;
static Def const& GetInternal(const std::string& key, static Def const& GetInternal(const std::string& key,
StackIter begin, StackIter end); StackIter begin, StackIter end, bool raise);
}; };
#endif #endif

View File

@ -130,7 +130,7 @@ public:
return true; return true;
} }
// First localize the definition in the current scope. // First localize the definition in the current scope.
this->GetDefinition(var); cmDefinitions::Raise(var, this->VarStack.rbegin(), this->VarStack.rend());
// Now update the definition in the parent scope. // Now update the definition in the parent scope.
it->Set(var, varDef); it->Set(var, varDef);