summaryrefslogtreecommitdiffstats
path: root/Source/cmGlobalGenerator.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-09-26 19:29:53 (GMT)
committerBrad King <brad.king@kitware.com>2016-09-26 19:35:39 (GMT)
commitcda8c782db80a1352ec6737b783558e35238bf17 (patch)
treeed394c893cd3b647fcf7c3e9c5bd1b6a553d4393 /Source/cmGlobalGenerator.cxx
parent1a5fddfe6d56733528ace3d15899b0739ea28054 (diff)
downloadCMake-cda8c782db80a1352ec6737b783558e35238bf17.zip
CMake-cda8c782db80a1352ec6737b783558e35238bf17.tar.gz
CMake-cda8c782db80a1352ec6737b783558e35238bf17.tar.bz2
cmGlobalGenerator: Optimize FindMakefile method with an index
This method is used by directory get/set APIs. With the new `SUBDIRECTORIES` and `BUILDSYSTEM_TARGETS` methods projects may now make heavy use of these APIs to traverse their directory structure and process targets. Make this faster by indexing the directory lookups.
Diffstat (limited to 'Source/cmGlobalGenerator.cxx')
-rw-r--r--Source/cmGlobalGenerator.cxx23
1 files changed, 17 insertions, 6 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 95747f2..4c62be7 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -1059,6 +1059,7 @@ void cmGlobalGenerator::Configure()
cmMakefile* dirMf = new cmMakefile(this, snapshot);
this->Makefiles.push_back(dirMf);
+ this->IndexMakefile(dirMf);
this->BinaryDirectories.insert(
this->CMakeInstance->GetHomeOutputDirectory());
@@ -1528,6 +1529,7 @@ void cmGlobalGenerator::ClearGeneratorMembers()
this->TargetDependencies.clear();
this->TargetSearchIndex.clear();
this->GeneratorTargetSearchIndex.clear();
+ this->MakefileSearchIndex.clear();
this->ProjectMap.clear();
this->RuleHashes.clear();
this->DirectoryContentMap.clear();
@@ -1805,6 +1807,7 @@ std::string cmGlobalGenerator::GenerateCMakeBuildCommand(
void cmGlobalGenerator::AddMakefile(cmMakefile* mf)
{
this->Makefiles.push_back(mf);
+ this->IndexMakefile(mf);
// update progress
// estimate how many lg there will be
@@ -1962,12 +1965,9 @@ void cmGlobalGenerator::FillProjectMap()
cmMakefile* cmGlobalGenerator::FindMakefile(const std::string& start_dir) const
{
- for (std::vector<cmMakefile*>::const_iterator it = this->Makefiles.begin();
- it != this->Makefiles.end(); ++it) {
- std::string sd = (*it)->GetCurrentSourceDirectory();
- if (sd == start_dir) {
- return *it;
- }
+ MakefileMap::const_iterator i = this->MakefileSearchIndex.find(start_dir);
+ if (i != this->MakefileSearchIndex.end()) {
+ return i->second;
}
return CM_NULLPTR;
}
@@ -2012,6 +2012,17 @@ void cmGlobalGenerator::IndexGeneratorTarget(cmGeneratorTarget* gt)
}
}
+void cmGlobalGenerator::IndexMakefile(cmMakefile* mf)
+{
+ // FIXME: add_subdirectory supports multiple build directories
+ // sharing the same source directory. We currently index only the
+ // first one, because that is what FindMakefile has always returned.
+ // All of its callers will need to be modified to support looking
+ // up directories by build directory path.
+ this->MakefileSearchIndex.insert(
+ MakefileMap::value_type(mf->GetCurrentSourceDirectory(), mf));
+}
+
cmTarget* cmGlobalGenerator::FindTargetImpl(std::string const& name) const
{
TargetMap::const_iterator i = this->TargetSearchIndex.find(name);