From c5b26f3bec0e6e18255802da53886eae30a74021 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 5 Apr 2014 11:40:38 +0200 Subject: 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. --- Source/cmGeneratorTarget.cxx | 18 +++++++++--------- Source/cmTarget.cxx | 39 ++++++++++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 01fad26..69a2977 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -636,26 +636,26 @@ cmTargetTraceDependencies // Queue all the source files already specified for the target. if (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY) { - std::vector sources; std::vector configs; this->Makefile->GetConfigurations(configs); if (configs.empty()) { configs.push_back(""); } + std::set emitted; for(std::vector::const_iterator ci = configs.begin(); ci != configs.end(); ++ci) { + std::vector sources; this->Target->GetSourceFiles(sources, *ci); - } - std::set emitted; - for(std::vector::const_iterator si = sources.begin(); - si != sources.end(); ++si) - { - if(emitted.insert(*si).second && this->SourcesQueued.insert(*si).second) + for(std::vector::const_iterator si = sources.begin(); + si != sources.end(); ++si) { - this->SourceQueue.push(*si); - this->Makefile->GetOrCreateSource(*si); + if(emitted.insert(*si).second && this->SourcesQueued.insert(*si).second) + { + this->SourceQueue.push(*si); + this->Makefile->GetOrCreateSource(*si); + } } } } diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 22be57f..d28ac3f 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -138,6 +138,10 @@ public: LinkClosureMapType; LinkClosureMapType LinkClosureMap; + typedef std::map > + SourceFilesMapType; + SourceFilesMapType SourceFilesMap; + struct TargetPropertyEntry { TargetPropertyEntry(cmsys::auto_ptr cge, const std::string &targetName = std::string()) @@ -793,19 +797,33 @@ void cmTarget::GetSourceFiles(std::vector &files, const std::string& config, cmTarget const* head) const { - std::vector srcs; - this->GetSourceFiles(srcs, config, head); - std::set emitted; + // Lookup any existing link implementation for this configuration. + TargetConfigPair key(head, cmSystemTools::UpperCase(config)); - for(std::vector::const_iterator i = srcs.begin(); - i != srcs.end(); ++i) + cmTargetInternals::SourceFilesMapType::iterator + it = this->Internal->SourceFilesMap.find(key); + if(it != this->Internal->SourceFilesMap.end()) + { + files = it->second; + } + else { - cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i); - if (emitted.insert(sf).second) + std::vector srcs; + this->GetSourceFiles(srcs, config, head); + + std::set emitted; + + for(std::vector::const_iterator i = srcs.begin(); + i != srcs.end(); ++i) { - files.push_back(sf); + cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i); + if (emitted.insert(sf).second) + { + files.push_back(sf); + } } + this->Internal->SourceFilesMap[key] = files; } } @@ -835,6 +853,7 @@ void cmTarget::AddSources(std::vector const& srcs) } if (!srcFiles.empty()) { + this->Internal->SourceFilesMap.clear(); cmListFileBacktrace lfbt; this->Makefile->GetBacktrace(lfbt); cmGeneratorExpression ge(lfbt); @@ -969,6 +988,7 @@ cmSourceFile* cmTarget::AddSource(const std::string& src) TargetPropertyEntryFinder(sfl)) == this->Internal->SourceEntries.end()) { + this->Internal->SourceFilesMap.clear(); cmListFileBacktrace lfbt; this->Makefile->GetBacktrace(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()); return; } + this->Internal->SourceFilesMap.clear(); cmListFileBacktrace lfbt; this->Makefile->GetBacktrace(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()); return; } - + this->Internal->SourceFilesMap.clear(); cmListFileBacktrace lfbt; this->Makefile->GetBacktrace(lfbt); cmGeneratorExpression ge(lfbt); -- cgit v0.12