Merge topic 'dev/variable-lookup'
e17a69bc
cmDefinitions: Use a hashmap for faster checks3b21705d
cmDefinitions: Avoid a find-then-insert when setting variables5abfde6c
cmDefinitions: Don't store parent lookups
This commit is contained in:
commit
bd20dd6b8a
|
@ -15,7 +15,8 @@
|
||||||
cmDefinitions::Def cmDefinitions::NoDef;
|
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::Def const&
|
||||||
cmDefinitions::GetInternal(const std::string& key)
|
cmDefinitions::GetInternal(const std::string& key) const
|
||||||
{
|
{
|
||||||
MapType::const_iterator i = this->Map.find(key);
|
MapType::const_iterator i = this->Map.find(key);
|
||||||
if(i != this->Map.end())
|
if(i != this->Map.end())
|
||||||
{
|
{
|
||||||
return i->second;
|
return i->second;
|
||||||
}
|
}
|
||||||
else if(cmDefinitions* up = this->Up)
|
if(cmDefinitions* up = this->Up)
|
||||||
{
|
{
|
||||||
// Query the parent scope and store the result locally.
|
// Query the parent scope.
|
||||||
Def def = up->GetInternal(key);
|
return up->GetInternal(key);
|
||||||
return this->Map.insert(MapType::value_type(key, def)).first->second;
|
|
||||||
}
|
}
|
||||||
return this->NoDef;
|
return this->NoDef;
|
||||||
}
|
}
|
||||||
|
@ -51,16 +51,7 @@ cmDefinitions::SetInternal(const std::string& key, Def const& def)
|
||||||
if(this->Up || def.Exists)
|
if(this->Up || def.Exists)
|
||||||
{
|
{
|
||||||
// In lower scopes we store keys, defined or not.
|
// In lower scopes we store keys, defined or not.
|
||||||
MapType::iterator i = this->Map.find(key);
|
return (this->Map[key] = def);
|
||||||
if(i == this->Map.end())
|
|
||||||
{
|
|
||||||
i = this->Map.insert(MapType::value_type(key, def)).first;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
i->second = def;
|
|
||||||
}
|
|
||||||
return i->second;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -71,12 +62,25 @@ 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);
|
Def const& def = this->GetInternal(key);
|
||||||
return def.Exists? def.c_str() : 0;
|
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)
|
const char* cmDefinitions::Set(const std::string& key, const char* value)
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
#define cmDefinitions_h
|
#define cmDefinitions_h
|
||||||
|
|
||||||
#include "cmStandardIncludes.h"
|
#include "cmStandardIncludes.h"
|
||||||
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
|
#include "cmsys/hash_map.hxx"
|
||||||
|
#endif
|
||||||
|
|
||||||
/** \class cmDefinitions
|
/** \class cmDefinitions
|
||||||
* \brief Store a scope of variable definitions for CMake language.
|
* \brief Store a scope of variable definitions for CMake language.
|
||||||
|
@ -33,9 +36,11 @@ public:
|
||||||
/** Returns the parent scope, if any. */
|
/** Returns the parent scope, if any. */
|
||||||
cmDefinitions* GetParent() const { return this->Up; }
|
cmDefinitions* GetParent() const { return this->Up; }
|
||||||
|
|
||||||
/** Get the value associated with a key; null if none.
|
/** 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) const;
|
||||||
const char* Get(const std::string& key);
|
|
||||||
|
/** Pull a variable from the parent. */
|
||||||
|
void Pull(const std::string& key);
|
||||||
|
|
||||||
/** Set (or unset if null) a value associated with a key. */
|
/** Set (or unset if null) a value associated with a key. */
|
||||||
const char* Set(const std::string& key, const char* value);
|
const char* Set(const std::string& key, const char* value);
|
||||||
|
@ -69,11 +74,15 @@ private:
|
||||||
cmDefinitions* Up;
|
cmDefinitions* Up;
|
||||||
|
|
||||||
// Local definitions, set or unset.
|
// Local definitions, set or unset.
|
||||||
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
|
typedef cmsys::hash_map<std::string, Def> MapType;
|
||||||
|
#else
|
||||||
typedef std::map<std::string, Def> MapType;
|
typedef std::map<std::string, Def> MapType;
|
||||||
|
#endif
|
||||||
MapType Map;
|
MapType Map;
|
||||||
|
|
||||||
// Internal query and update methods.
|
// 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);
|
Def const& SetInternal(const std::string& key, Def const& def);
|
||||||
|
|
||||||
// Implementation of Closure() method.
|
// Implementation of Closure() method.
|
||||||
|
|
|
@ -4422,7 +4422,7 @@ void cmMakefile::RaiseScope(const std::string& var, const char *varDef)
|
||||||
if(cmDefinitions* up = cur.GetParent())
|
if(cmDefinitions* up = cur.GetParent())
|
||||||
{
|
{
|
||||||
// First localize the definition in the current scope.
|
// First localize the definition in the current scope.
|
||||||
cur.Get(var);
|
cur.Pull(var);
|
||||||
|
|
||||||
// Now update the definition in the parent scope.
|
// Now update the definition in the parent scope.
|
||||||
up->Set(var, varDef);
|
up->Set(var, varDef);
|
||||||
|
|
Loading…
Reference in New Issue