mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-27 01:19:31 -05:00
Merge topic 'getsource_optimize'
2d1e5ada cmMakefile: Improve performance of GetSource for known files
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1764
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user