diff options
author | Brad King <brad.king@kitware.com> | 2016-02-08 17:37:47 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-02-08 18:08:11 (GMT) |
commit | 6cbf6a51976c9092f84ef4a90d35fb6fd60f5898 (patch) | |
tree | 3dfad2feee26d2e3d7100655029dbc4d2d27ab26 /Source/cmGlobalGenerator.cxx | |
parent | a5a5a6857241c21d306661d723b749839f4c6e1a (diff) | |
download | CMake-6cbf6a51976c9092f84ef4a90d35fb6fd60f5898.zip CMake-6cbf6a51976c9092f84ef4a90d35fb6fd60f5898.tar.gz CMake-6cbf6a51976c9092f84ef4a90d35fb6fd60f5898.tar.bz2 |
Fix internal target lookup performance regression
Refactoring in commit v3.5.0-rc1~272^2~13 (cmGlobalGenerator: Remove
direct storage of targets, 2015-10-25) replaced an efficient data
structure mapping from target name to cmTarget instance with a linear
search. Lookups through cmGlobalGenerator::FindTarget are done a lot.
Restore the efficient mapping structure with a name indicating its
purpose.
Reported-by: Bartosz Kosiorek <gang65@poczta.onet.pl>
Diffstat (limited to 'Source/cmGlobalGenerator.cxx')
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 46 |
1 files changed, 13 insertions, 33 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index d7bec44..65e7b12 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1649,6 +1649,7 @@ void cmGlobalGenerator::ClearGeneratorMembers() this->ExportSets.clear(); this->TargetDependencies.clear(); + this->TargetSearchIndex.clear(); this->ProjectMap.clear(); this->RuleHashes.clear(); this->DirectoryContentMap.clear(); @@ -2177,18 +2178,20 @@ bool cmGlobalGenerator::IsAlias(const std::string& name) const return this->AliasTargets.find(name) != this->AliasTargets.end(); } +void cmGlobalGenerator::IndexTarget(cmTarget* t) +{ + if (!t->IsImported() || t->IsImportedGloballyVisible()) + { + this->TargetSearchIndex[t->GetName()] = t; + } +} + cmTarget* cmGlobalGenerator::FindTargetImpl(std::string const& name) const { - for (unsigned int i = 0; i < this->Makefiles.size(); ++i) + TargetMap::const_iterator i = this->TargetSearchIndex.find(name); + if (i != this->TargetSearchIndex.end()) { - cmTargets& tgts = this->Makefiles[i]->GetTargets(); - for (cmTargets::iterator it = tgts.begin(); it != tgts.end(); ++it) - { - if (it->second.GetName() == name) - { - return &it->second; - } - } + return i->second; } return 0; } @@ -2212,25 +2215,6 @@ cmGlobalGenerator::FindGeneratorTargetImpl(std::string const& name) const return 0; } -cmTarget* -cmGlobalGenerator::FindImportedTargetImpl(std::string const& name) const -{ - for (unsigned int i = 0; i < this->Makefiles.size(); ++i) - { - const std::vector<cmTarget*>& tgts = - this->Makefiles[i]->GetOwnedImportedTargets(); - for (std::vector<cmTarget*>::const_iterator it = tgts.begin(); - it != tgts.end(); ++it) - { - if ((*it)->GetName() == name && (*it)->IsImportedGloballyVisible()) - { - return *it; - } - } - } - return 0; -} - cmGeneratorTarget* cmGlobalGenerator::FindImportedGeneratorTargetImpl( std::string const& name) const { @@ -2264,11 +2248,7 @@ cmGlobalGenerator::FindTarget(const std::string& name, return this->FindTargetImpl(ai->second); } } - if (cmTarget* tgt = this->FindTargetImpl(name)) - { - return tgt; - } - return this->FindImportedTargetImpl(name); + return this->FindTargetImpl(name); } cmGeneratorTarget* |