Speed up graph traversal for project->targets map

The cmGlobalGenerator::AddTargetDepends method traces the dependencies
of targets recursively to collect the complete set of targets needed for
a given project (for VS .sln files).  This commit teaches the method to
avoid tracing its dependencies more than once.  Otherwise the code does
an all-paths walk needlessly.
This commit is contained in:
Brad King 2009-09-02 16:06:43 -04:00
parent 7e20db0224
commit 0af3b3b802
1 changed files with 5 additions and 7 deletions

View File

@ -1971,14 +1971,12 @@ cmGlobalGenerator::AddTargetDepends(cmTarget* target,
projectTargets) projectTargets)
{ {
// add the target itself // add the target itself
projectTargets.insert(target); if(projectTargets.insert(target).second)
// get the direct depends of target {
// This is the first time we have encountered the target.
// Recursively follow its dependencies.
cmGlobalGenerator::TargetDependSet const& tset cmGlobalGenerator::TargetDependSet const& tset
= this->GetTargetDirectDepends(*target); = this->GetTargetDirectDepends(*target);
if(tset.size())
{
// if there are targets that depend on target
// add them and their depends as well
for(cmGlobalGenerator::TargetDependSet::const_iterator i = for(cmGlobalGenerator::TargetDependSet::const_iterator i =
tset.begin(); i != tset.end(); ++i) tset.begin(); i != tset.end(); ++i)
{ {