diff options
author | Brad King <brad.king@kitware.com> | 2016-02-08 17:50:56 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-02-08 18:08:11 (GMT) |
commit | 9b7d5871b86036da009119e14f54d161f2d44f24 (patch) | |
tree | ad8e06f9fe4d8f7e2b8c8f3a4f1adaea814ee3e5 /Source/cmGlobalGenerator.cxx | |
parent | 6cbf6a51976c9092f84ef4a90d35fb6fd60f5898 (diff) | |
download | CMake-9b7d5871b86036da009119e14f54d161f2d44f24.zip CMake-9b7d5871b86036da009119e14f54d161f2d44f24.tar.gz CMake-9b7d5871b86036da009119e14f54d161f2d44f24.tar.bz2 |
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>
Diffstat (limited to 'Source/cmGlobalGenerator.cxx')
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 49 |
1 files changed, 14 insertions, 35 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 65e7b12..fc8cf06 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1650,6 +1650,7 @@ void cmGlobalGenerator::ClearGeneratorMembers() this->ExportSets.clear(); this->TargetDependencies.clear(); this->TargetSearchIndex.clear(); + this->GeneratorTargetSearchIndex.clear(); this->ProjectMap.clear(); this->RuleHashes.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 { TargetMap::const_iterator i = this->TargetSearchIndex.find(name); @@ -2199,37 +2208,11 @@ cmTarget* cmGlobalGenerator::FindTargetImpl(std::string const& name) const cmGeneratorTarget* 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 = - 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 i->second; } return 0; } @@ -2260,11 +2243,7 @@ cmGlobalGenerator::FindGeneratorTarget(const std::string& name) const { return this->FindGeneratorTargetImpl(ai->second); } - if (cmGeneratorTarget* tgt = this->FindGeneratorTargetImpl(name)) - { - return tgt; - } - return this->FindImportedGeneratorTargetImpl(name); + return this->FindGeneratorTargetImpl(name); } //---------------------------------------------------------------------------- |