mirror of
https://github.com/Kitware/CMake.git
synced 2026-08-07 16:20:51 +00:00
cmLocalGenerator: change ImportedGeneratorTargets from vector to map
For large number of targets significant amount of time is spent in cmLocalGenerator::FindGeneratorTargetToUse, which uses find_if on a vector to locate the given target. Using a map instead of vector for ImportedGeneratorTargets (as done for cmMakefile::ImportedTargets) provides a significant speedup (up to factor of 2).
This commit is contained in:
committed by
Brad King
parent
4443adc1c0
commit
aed227fd5a
@@ -553,14 +553,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->GeneratorTargetSearchIndex.insert(
|
this->GeneratorTargetSearchIndex.emplace(gt->GetName(), gt);
|
||||||
std::pair<std::string, cmGeneratorTarget*>(gt->GetName(), gt));
|
|
||||||
this->GlobalGenerator->IndexGeneratorTarget(gt);
|
this->GlobalGenerator->IndexGeneratorTarget(gt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmLocalGenerator::AddImportedGeneratorTarget(cmGeneratorTarget* gt)
|
void cmLocalGenerator::AddImportedGeneratorTarget(cmGeneratorTarget* gt)
|
||||||
{
|
{
|
||||||
this->ImportedGeneratorTargets.push_back(gt);
|
this->ImportedGeneratorTargets.emplace(gt->GetName(), gt);
|
||||||
this->GlobalGenerator->IndexGeneratorTarget(gt);
|
this->GlobalGenerator->IndexGeneratorTarget(gt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -569,22 +568,6 @@ void cmLocalGenerator::AddOwnedImportedGeneratorTarget(cmGeneratorTarget* gt)
|
|||||||
this->OwnedImportedGeneratorTargets.push_back(gt);
|
this->OwnedImportedGeneratorTargets.push_back(gt);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NamedGeneratorTargetFinder
|
|
||||||
{
|
|
||||||
NamedGeneratorTargetFinder(std::string const& name)
|
|
||||||
: Name(name)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator()(cmGeneratorTarget* tgt)
|
|
||||||
{
|
|
||||||
return tgt->GetName() == this->Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string Name;
|
|
||||||
};
|
|
||||||
|
|
||||||
cmGeneratorTarget* cmLocalGenerator::FindLocalNonAliasGeneratorTarget(
|
cmGeneratorTarget* cmLocalGenerator::FindLocalNonAliasGeneratorTarget(
|
||||||
const std::string& name) const
|
const std::string& name) const
|
||||||
{
|
{
|
||||||
@@ -1395,11 +1378,10 @@ void cmLocalGenerator::AddLanguageFlagsForLinking(
|
|||||||
cmGeneratorTarget* cmLocalGenerator::FindGeneratorTargetToUse(
|
cmGeneratorTarget* cmLocalGenerator::FindGeneratorTargetToUse(
|
||||||
const std::string& name) const
|
const std::string& name) const
|
||||||
{
|
{
|
||||||
std::vector<cmGeneratorTarget*>::const_iterator imported = std::find_if(
|
GeneratorTargetMap::const_iterator imported =
|
||||||
this->ImportedGeneratorTargets.begin(),
|
this->ImportedGeneratorTargets.find(name);
|
||||||
this->ImportedGeneratorTargets.end(), NamedGeneratorTargetFinder(name));
|
|
||||||
if (imported != this->ImportedGeneratorTargets.end()) {
|
if (imported != this->ImportedGeneratorTargets.end()) {
|
||||||
return *imported;
|
return imported->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmGeneratorTarget* t = this->FindLocalNonAliasGeneratorTarget(name)) {
|
if (cmGeneratorTarget* t = this->FindLocalNonAliasGeneratorTarget(name)) {
|
||||||
|
|||||||
@@ -389,7 +389,7 @@ protected:
|
|||||||
std::vector<cmGeneratorTarget*> GeneratorTargets;
|
std::vector<cmGeneratorTarget*> GeneratorTargets;
|
||||||
|
|
||||||
std::set<cmGeneratorTarget const*> WarnCMP0063;
|
std::set<cmGeneratorTarget const*> WarnCMP0063;
|
||||||
std::vector<cmGeneratorTarget*> ImportedGeneratorTargets;
|
GeneratorTargetMap ImportedGeneratorTargets;
|
||||||
std::vector<cmGeneratorTarget*> OwnedImportedGeneratorTargets;
|
std::vector<cmGeneratorTarget*> OwnedImportedGeneratorTargets;
|
||||||
std::map<std::string, std::string> AliasTargets;
|
std::map<std::string, std::string> AliasTargets;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user