summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-02-26 14:00:44 (GMT)
committerKitware Robot <kwrobot@kitware.com>2018-02-26 14:00:51 (GMT)
commit3bc18cd0fb0174af4e34dfc42263553e2127c4eb (patch)
treeff101e9366061c5dc46952f829e258d45a90e89e
parente4df2313c172592cc83e4f1cd6a3f358cc07cb22 (diff)
parent2d1e5adaeb5827ebdd3111388f2fcda98656b8ac (diff)
downloadCMake-3bc18cd0fb0174af4e34dfc42263553e2127c4eb.zip
CMake-3bc18cd0fb0174af4e34dfc42263553e2127c4eb.tar.gz
CMake-3bc18cd0fb0174af4e34dfc42263553e2127c4eb.tar.bz2
Merge topic 'getsource_optimize'
2d1e5ada cmMakefile: Improve performance of GetSource for known files Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !1764
-rw-r--r--Source/cmMakefile.cxx12
-rw-r--r--Source/cmMakefile.h3
2 files changed, 15 insertions, 0 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 82c6e81..47d75af 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -3138,6 +3138,14 @@ void cmMakefile::SetArgcArgv(const std::vector<std::string>& args)
cmSourceFile* cmMakefile::GetSource(const std::string& sourceName,
cmSourceFileLocationKind kind) const
{
+ // First check "Known" paths (avoids the creation of cmSourceFileLocation)
+ if (kind == cmSourceFileLocationKind::Known) {
+ auto sfsi = this->KnownFileSearchIndex.find(sourceName);
+ if (sfsi != this->KnownFileSearchIndex.end()) {
+ return sfsi->second;
+ }
+ }
+
cmSourceFileLocation sfl(this, sourceName, kind);
auto name = this->GetCMakeInstance()->StripExtension(sfl.GetName());
#if defined(_WIN32) || defined(__APPLE__)
@@ -3170,6 +3178,10 @@ cmSourceFile* cmMakefile::CreateSource(const std::string& sourceName,
name = cmSystemTools::LowerCase(name);
#endif
this->SourceFileSearchIndex[name].push_back(sf);
+ // for "Known" paths add direct lookup (used for faster lookup in GetSource)
+ if (kind == cmSourceFileLocationKind::Known) {
+ this->KnownFileSearchIndex[sourceName] = sf;
+ }
return sf;
}
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 5a30790..95ba53a 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -861,6 +861,9 @@ protected:
typedef std::unordered_map<std::string, SourceFileVec> SourceFileMap;
SourceFileMap SourceFileSearchIndex;
+ // For "Known" paths we can store a direct filename to cmSourceFile map
+ std::unordered_map<std::string, cmSourceFile*> KnownFileSearchIndex;
+
// Tests
std::map<std::string, cmTest*> Tests;