Improve internal generator target structure lookup
In commit v3.5.0-rc1~272^2~6 (cmGlobalGenerator: Add FindGeneratorTarget API, 2015-10-25) a lookup was implemented via linear search. Replace it with an efficient data structure. Suggested-by: Stephen Kelly <steveire@gmail.com>
This commit is contained in:
parent
6cbf6a5197
commit
9b7d5871b8
|
@ -1650,6 +1650,7 @@ void cmGlobalGenerator::ClearGeneratorMembers()
|
||||||
this->ExportSets.clear();
|
this->ExportSets.clear();
|
||||||
this->TargetDependencies.clear();
|
this->TargetDependencies.clear();
|
||||||
this->TargetSearchIndex.clear();
|
this->TargetSearchIndex.clear();
|
||||||
|
this->GeneratorTargetSearchIndex.clear();
|
||||||
this->ProjectMap.clear();
|
this->ProjectMap.clear();
|
||||||
this->RuleHashes.clear();
|
this->RuleHashes.clear();
|
||||||
this->DirectoryContentMap.clear();
|
this->DirectoryContentMap.clear();
|
||||||
|
@ -2186,6 +2187,14 @@ void cmGlobalGenerator::IndexTarget(cmTarget* t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmGlobalGenerator::IndexGeneratorTarget(cmGeneratorTarget* gt)
|
||||||
|
{
|
||||||
|
if (!gt->IsImported() || gt->IsImportedGloballyVisible())
|
||||||
|
{
|
||||||
|
this->GeneratorTargetSearchIndex[gt->GetName()] = gt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cmTarget* cmGlobalGenerator::FindTargetImpl(std::string const& name) const
|
cmTarget* cmGlobalGenerator::FindTargetImpl(std::string const& name) const
|
||||||
{
|
{
|
||||||
TargetMap::const_iterator i = this->TargetSearchIndex.find(name);
|
TargetMap::const_iterator i = this->TargetSearchIndex.find(name);
|
||||||
|
@ -2199,37 +2208,11 @@ cmTarget* cmGlobalGenerator::FindTargetImpl(std::string const& name) const
|
||||||
cmGeneratorTarget*
|
cmGeneratorTarget*
|
||||||
cmGlobalGenerator::FindGeneratorTargetImpl(std::string const& name) const
|
cmGlobalGenerator::FindGeneratorTargetImpl(std::string const& name) const
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
|
GeneratorTargetMap::const_iterator i =
|
||||||
|
this->GeneratorTargetSearchIndex.find(name);
|
||||||
|
if (i != this->GeneratorTargetSearchIndex.end())
|
||||||
{
|
{
|
||||||
const std::vector<cmGeneratorTarget*>& tgts =
|
return i->second;
|
||||||
this->LocalGenerators[i]->GetGeneratorTargets();
|
|
||||||
for (std::vector<cmGeneratorTarget*>::const_iterator it = tgts.begin();
|
|
||||||
it != tgts.end(); ++it)
|
|
||||||
{
|
|
||||||
if ((*it)->GetName() == name)
|
|
||||||
{
|
|
||||||
return *it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
cmGeneratorTarget* cmGlobalGenerator::FindImportedGeneratorTargetImpl(
|
|
||||||
std::string const& name) const
|
|
||||||
{
|
|
||||||
for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i)
|
|
||||||
{
|
|
||||||
const std::vector<cmGeneratorTarget*>& tgts =
|
|
||||||
this->LocalGenerators[i]->GetImportedGeneratorTargets();
|
|
||||||
for (std::vector<cmGeneratorTarget*>::const_iterator it = tgts.begin();
|
|
||||||
it != tgts.end(); ++it)
|
|
||||||
{
|
|
||||||
if ((*it)->IsImportedGloballyVisible() && (*it)->GetName() == name)
|
|
||||||
{
|
|
||||||
return *it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2260,11 +2243,7 @@ cmGlobalGenerator::FindGeneratorTarget(const std::string& name) const
|
||||||
{
|
{
|
||||||
return this->FindGeneratorTargetImpl(ai->second);
|
return this->FindGeneratorTargetImpl(ai->second);
|
||||||
}
|
}
|
||||||
if (cmGeneratorTarget* tgt = this->FindGeneratorTargetImpl(name))
|
return this->FindGeneratorTargetImpl(name);
|
||||||
{
|
|
||||||
return tgt;
|
|
||||||
}
|
|
||||||
return this->FindImportedGeneratorTargetImpl(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
|
@ -279,6 +279,7 @@ public:
|
||||||
bool needDisk = true);
|
bool needDisk = true);
|
||||||
|
|
||||||
void IndexTarget(cmTarget* t);
|
void IndexTarget(cmTarget* t);
|
||||||
|
void IndexGeneratorTarget(cmGeneratorTarget* gt);
|
||||||
|
|
||||||
static bool IsReservedTarget(std::string const& name);
|
static bool IsReservedTarget(std::string const& name);
|
||||||
|
|
||||||
|
@ -435,16 +436,21 @@ private:
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
# ifdef CMake_HAVE_CXX11_UNORDERED_MAP
|
# ifdef CMake_HAVE_CXX11_UNORDERED_MAP
|
||||||
typedef std::unordered_map<std::string, cmTarget*> TargetMap;
|
typedef std::unordered_map<std::string, cmTarget*> TargetMap;
|
||||||
|
typedef std::unordered_map<std::string, cmGeneratorTarget*>
|
||||||
|
GeneratorTargetMap;
|
||||||
# else
|
# else
|
||||||
typedef cmsys::hash_map<std::string, cmTarget*> TargetMap;
|
typedef cmsys::hash_map<std::string, cmTarget*> TargetMap;
|
||||||
|
typedef cmsys::hash_map<std::string, cmGeneratorTarget*> GeneratorTargetMap;
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
typedef std::map<std::string,cmTarget *> TargetMap;
|
typedef std::map<std::string,cmTarget *> TargetMap;
|
||||||
|
typedef std::map<std::string,cmGeneratorTarget *> GeneratorTargetMap;
|
||||||
#endif
|
#endif
|
||||||
// Map efficiently from target name to cmTarget instance.
|
// Map efficiently from target name to cmTarget instance.
|
||||||
// Do not use this structure for looping over all targets.
|
// Do not use this structure for looping over all targets.
|
||||||
// It contains both normal and globally visible imported targets.
|
// It contains both normal and globally visible imported targets.
|
||||||
TargetMap TargetSearchIndex;
|
TargetMap TargetSearchIndex;
|
||||||
|
GeneratorTargetMap GeneratorTargetSearchIndex;
|
||||||
|
|
||||||
cmMakefile* TryCompileOuterMakefile;
|
cmMakefile* TryCompileOuterMakefile;
|
||||||
// If you add a new map here, make sure it is copied
|
// If you add a new map here, make sure it is copied
|
||||||
|
|
|
@ -455,11 +455,13 @@ void cmLocalGenerator::GenerateInstallRules()
|
||||||
void cmLocalGenerator::AddGeneratorTarget(cmGeneratorTarget* gt)
|
void cmLocalGenerator::AddGeneratorTarget(cmGeneratorTarget* gt)
|
||||||
{
|
{
|
||||||
this->GeneratorTargets.push_back(gt);
|
this->GeneratorTargets.push_back(gt);
|
||||||
|
this->GlobalGenerator->IndexGeneratorTarget(gt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmLocalGenerator::AddImportedGeneratorTarget(cmGeneratorTarget* gt)
|
void cmLocalGenerator::AddImportedGeneratorTarget(cmGeneratorTarget* gt)
|
||||||
{
|
{
|
||||||
this->ImportedGeneratorTargets.push_back(gt);
|
this->ImportedGeneratorTargets.push_back(gt);
|
||||||
|
this->GlobalGenerator->IndexGeneratorTarget(gt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmLocalGenerator::AddOwnedImportedGeneratorTarget(cmGeneratorTarget* gt)
|
void cmLocalGenerator::AddOwnedImportedGeneratorTarget(cmGeneratorTarget* gt)
|
||||||
|
|
Loading…
Reference in New Issue