ENH: some performance optimizations

This commit is contained in:
Ken Martin 2006-04-11 12:51:20 -04:00
parent acf33ba191
commit 535acdc7a0
5 changed files with 40 additions and 18 deletions

View File

@ -584,7 +584,8 @@ void cmGlobalGenerator::Configure()
// Setup relative path generation.
this->ConfigureRelativePaths();
this->TotalTargets.clear();
// start with this directory
cmLocalGenerator *lg = this->CreateLocalGenerator();
this->LocalGenerators.push_back(lg);
@ -1019,18 +1020,29 @@ cmTarget* cmGlobalGenerator::FindTarget(const char* project,
const char* name)
{
std::vector<cmLocalGenerator*>* gens = &this->LocalGenerators;
// if project specific
if(project)
{
gens = &this->ProjectMap[project];
}
for(unsigned int i = 0; i < gens->size(); ++i)
{
cmTarget* ret = (*gens)[i]->GetMakefile()->FindTarget(name);
if(ret)
for(unsigned int i = 0; i < gens->size(); ++i)
{
return ret;
cmTarget* ret = (*gens)[i]->GetMakefile()->FindTarget(name);
if(ret)
{
return ret;
}
}
}
// if all projects/directories
else
{
std::map<cmStdString,cmTarget *>::iterator i = this->TotalTargets.find(name);
if (i == this->TotalTargets.end())
{
return 0;
}
return i->second;
}
return 0;
}

View File

@ -175,6 +175,9 @@ public:
configuration. This is valid during generation only. */
cmTargetManifest const& GetTargetManifest() { return this->TargetManifest; }
void AddTarget(cmTargets::value_type &v) {
this->TotalTargets.insert(std::pair<cmStdString,cmTarget *>(v.first,&v.second));};
/** Support for multiple custom command outputs. */
virtual void CheckMultipleOutputs(cmMakefile* mf, bool verbose);
@ -233,6 +236,9 @@ private:
// using relative paths is unsafe.
std::string RelativePathTopSource;
std::string RelativePathTopBinary;
// this is used to improve performance
std::map<cmStdString,cmTarget *> TotalTargets;
};
#endif

View File

@ -709,10 +709,8 @@ cmLocalUnixMakefileGenerator3
std::string
cmLocalUnixMakefileGenerator3::GetRelativeTargetDirectory(cmTarget& target)
{
std::string dir = this->Makefile->GetStartOutputDirectory();
dir += "/";
std::string dir = this->HomeRelativeOutputPath;
dir += this->GetTargetDirectory(target);
dir = cmSystemTools::RelativePath(this->Makefile->GetHomeOutputDirectory(), dir.c_str());
return this->Convert(dir.c_str(),NONE,MAKEFILE);
}
@ -907,6 +905,7 @@ cmLocalUnixMakefileGenerator3::AppendEcho(std::vector<std::string>& commands,
// Echo one line at a time.
std::string line;
line.reserve(200);
for(const char* c = text;; ++c)
{
if(*c == '\n' || *c == '\0')

View File

@ -774,7 +774,9 @@ void cmMakefile::AddUtilityCommand(const char* utilityName, bool all,
target.GetPostBuildCommands().push_back(cc);
// Add the target to the set of targets.
this->Targets.insert(cmTargets::value_type(utilityName, target));
cmTargets::iterator it =
this->Targets.insert(cmTargets::value_type(utilityName,target)).first;
this->LocalGenerator->GetGlobalGenerator()->AddTarget(*it);
}
void cmMakefile::AddDefineFlag(const char* flag)
@ -1152,7 +1154,9 @@ void cmMakefile::AddLibrary(const char* lname, int shared,
target.GetSourceLists() = srcs;
target.SetMakefile(this);
this->AddGlobalLinkInformation(lname, target);
this->Targets.insert(cmTargets::value_type(lname,target));
cmTargets::iterator it =
this->Targets.insert(cmTargets::value_type(lname,target)).first;
this->LocalGenerator->GetGlobalGenerator()->AddTarget(*it);
}
cmTarget* cmMakefile::AddExecutable(const char *exeName,
@ -1166,6 +1170,7 @@ cmTarget* cmMakefile::AddExecutable(const char *exeName,
this->AddGlobalLinkInformation(exeName, target);
cmTargets::iterator it =
this->Targets.insert(cmTargets::value_type(exeName,target)).first;
this->LocalGenerator->GetGlobalGenerator()->AddTarget(*it);
return &it->second;
}
@ -2560,14 +2565,13 @@ bool cmMakefile::GetPropertyAsBool(const char* prop) const
cmTarget* cmMakefile::FindTarget(const char* name)
{
cmTargets& tgts = this->GetTargets();
for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
cmTargets::iterator i = tgts.find(name);
if (i == tgts.end())
{
if(l->first == name)
{
return &l->second;
}
return 0;
}
return 0;
return &i->second;
}
cmTest* cmMakefile::CreateTest(const char* testName)

View File

@ -414,6 +414,7 @@ public:
cmTarget* FindTarget(const char* name);
/**
* Get a list of include directories in the build.
*/