cmTarget: Cache the cmSourceFiles in GetSourceFiles.

Avoid calling GetSourceFiles with the same result container multiple
times when tracing target dependencies.  The result from the previous
configuration is cached and used later otherwise.
This commit is contained in:
Stephen Kelly 2014-04-05 11:40:38 +02:00
parent eb163f37d4
commit c5b26f3bec
2 changed files with 39 additions and 18 deletions

View File

@ -636,19 +636,18 @@ cmTargetTraceDependencies
// Queue all the source files already specified for the target. // Queue all the source files already specified for the target.
if (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY) if (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
{ {
std::vector<std::string> sources;
std::vector<std::string> configs; std::vector<std::string> configs;
this->Makefile->GetConfigurations(configs); this->Makefile->GetConfigurations(configs);
if (configs.empty()) if (configs.empty())
{ {
configs.push_back(""); configs.push_back("");
} }
std::set<std::string> emitted;
for(std::vector<std::string>::const_iterator ci = configs.begin(); for(std::vector<std::string>::const_iterator ci = configs.begin();
ci != configs.end(); ++ci) ci != configs.end(); ++ci)
{ {
std::vector<std::string> sources;
this->Target->GetSourceFiles(sources, *ci); this->Target->GetSourceFiles(sources, *ci);
}
std::set<std::string> emitted;
for(std::vector<std::string>::const_iterator si = sources.begin(); for(std::vector<std::string>::const_iterator si = sources.begin();
si != sources.end(); ++si) si != sources.end(); ++si)
{ {
@ -659,6 +658,7 @@ cmTargetTraceDependencies
} }
} }
} }
}
// Queue pre-build, pre-link, and post-build rule dependencies. // Queue pre-build, pre-link, and post-build rule dependencies.
this->CheckCustomCommands(this->Target->GetPreBuildCommands()); this->CheckCustomCommands(this->Target->GetPreBuildCommands());

View File

@ -138,6 +138,10 @@ public:
LinkClosureMapType; LinkClosureMapType;
LinkClosureMapType LinkClosureMap; LinkClosureMapType LinkClosureMap;
typedef std::map<TargetConfigPair, std::vector<cmSourceFile*> >
SourceFilesMapType;
SourceFilesMapType SourceFilesMap;
struct TargetPropertyEntry { struct TargetPropertyEntry {
TargetPropertyEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge, TargetPropertyEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge,
const std::string &targetName = std::string()) const std::string &targetName = std::string())
@ -792,6 +796,18 @@ cmTarget::GetConfigCommonSourceFiles(std::vector<cmSourceFile*>& files) const
void cmTarget::GetSourceFiles(std::vector<cmSourceFile*> &files, void cmTarget::GetSourceFiles(std::vector<cmSourceFile*> &files,
const std::string& config, const std::string& config,
cmTarget const* head) const cmTarget const* head) const
{
// Lookup any existing link implementation for this configuration.
TargetConfigPair key(head, cmSystemTools::UpperCase(config));
cmTargetInternals::SourceFilesMapType::iterator
it = this->Internal->SourceFilesMap.find(key);
if(it != this->Internal->SourceFilesMap.end())
{
files = it->second;
}
else
{ {
std::vector<std::string> srcs; std::vector<std::string> srcs;
this->GetSourceFiles(srcs, config, head); this->GetSourceFiles(srcs, config, head);
@ -807,6 +823,8 @@ void cmTarget::GetSourceFiles(std::vector<cmSourceFile*> &files,
files.push_back(sf); files.push_back(sf);
} }
} }
this->Internal->SourceFilesMap[key] = files;
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -835,6 +853,7 @@ void cmTarget::AddSources(std::vector<std::string> const& srcs)
} }
if (!srcFiles.empty()) if (!srcFiles.empty())
{ {
this->Internal->SourceFilesMap.clear();
cmListFileBacktrace lfbt; cmListFileBacktrace lfbt;
this->Makefile->GetBacktrace(lfbt); this->Makefile->GetBacktrace(lfbt);
cmGeneratorExpression ge(lfbt); cmGeneratorExpression ge(lfbt);
@ -969,6 +988,7 @@ cmSourceFile* cmTarget::AddSource(const std::string& src)
TargetPropertyEntryFinder(sfl)) TargetPropertyEntryFinder(sfl))
== this->Internal->SourceEntries.end()) == this->Internal->SourceEntries.end())
{ {
this->Internal->SourceFilesMap.clear();
cmListFileBacktrace lfbt; cmListFileBacktrace lfbt;
this->Makefile->GetBacktrace(lfbt); this->Makefile->GetBacktrace(lfbt);
cmGeneratorExpression ge(lfbt); cmGeneratorExpression ge(lfbt);
@ -1738,6 +1758,7 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
return; return;
} }
this->Internal->SourceFilesMap.clear();
cmListFileBacktrace lfbt; cmListFileBacktrace lfbt;
this->Makefile->GetBacktrace(lfbt); this->Makefile->GetBacktrace(lfbt);
cmGeneratorExpression ge(lfbt); cmGeneratorExpression ge(lfbt);
@ -1824,7 +1845,7 @@ void cmTarget::AppendProperty(const std::string& prop, const char* value,
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
return; return;
} }
this->Internal->SourceFilesMap.clear();
cmListFileBacktrace lfbt; cmListFileBacktrace lfbt;
this->Makefile->GetBacktrace(lfbt); this->Makefile->GetBacktrace(lfbt);
cmGeneratorExpression ge(lfbt); cmGeneratorExpression ge(lfbt);