summaryrefslogtreecommitdiffstats
path: root/Source/cmMakefile.cxx
diff options
context:
space:
mode:
authorNicolas Despres <nicolas.despres@gmail.com>2013-08-06 16:12:50 (GMT)
committerBrad King <brad.king@kitware.com>2013-08-06 20:17:13 (GMT)
commit2268c41a057d948ad6773c5145ee5bf6d19ea3bf (patch)
tree9f5b1b81cdcbd0d496f331bc659b542fd9e99d9f /Source/cmMakefile.cxx
parenteccb39d7f44f97d395b75b985b4e18178b72df8c (diff)
downloadCMake-2268c41a057d948ad6773c5145ee5bf6d19ea3bf.zip
CMake-2268c41a057d948ad6773c5145ee5bf6d19ea3bf.tar.gz
CMake-2268c41a057d948ad6773c5145ee5bf6d19ea3bf.tar.bz2
Optimize custom command full-path dependency lookup
In the common case of custom command dependencies specified via full path optimize the implementation of GetSourceFileWithOutput using a (hash) map. This is significantly faster than the existing linear search. In the non-full-path case fall back to the existing linear suffix search.
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r--Source/cmMakefile.cxx43
1 files changed, 42 insertions, 1 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index aae92dd..08c9763 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -150,6 +150,7 @@ cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals)
this->Initialize();
this->CheckSystemVars = mf.CheckSystemVars;
this->ListFileStack = mf.ListFileStack;
+ this->OutputToSource = mf.OutputToSource;
}
//----------------------------------------------------------------------------
@@ -1010,11 +1011,32 @@ cmMakefile::AddCustomCommandToOutput(const std::vector<std::string>& outputs,
cc->SetEscapeOldStyle(escapeOldStyle);
cc->SetEscapeAllowMakeVars(true);
file->SetCustomCommand(cc);
+ this->UpdateOutputToSourceMap(outputs, file);
}
return file;
}
//----------------------------------------------------------------------------
+void
+cmMakefile::UpdateOutputToSourceMap(std::vector<std::string> const& outputs,
+ cmSourceFile* source)
+{
+ for(std::vector<std::string>::const_iterator o = outputs.begin();
+ o != outputs.end(); ++o)
+ {
+ this->UpdateOutputToSourceMap(*o, source);
+ }
+}
+
+//----------------------------------------------------------------------------
+void
+cmMakefile::UpdateOutputToSourceMap(std::string const& output,
+ cmSourceFile* source)
+{
+ this->OutputToSource[output] = source;
+}
+
+//----------------------------------------------------------------------------
cmSourceFile*
cmMakefile::AddCustomCommandToOutput(const char* output,
const std::vector<std::string>& depends,
@@ -1994,7 +2016,7 @@ cmMakefile::AddNewTarget(cmTarget::TargetType type, const char* name)
return &it->second;
}
-cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname)
+cmSourceFile *cmMakefile::LinearGetSourceFileWithOutput(const char *cname)
{
std::string name = cname;
std::string out;
@@ -2030,6 +2052,25 @@ cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname)
return 0;
}
+cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname)
+{
+ std::string name = cname;
+
+ // If the queried path is not absolute we use the backward compatible
+ // linear-time search for an output with a matching suffix.
+ if(!cmSystemTools::FileIsFullPath(cname))
+ {
+ return LinearGetSourceFileWithOutput(cname);
+ }
+ // Otherwise we use an efficient lookup map.
+ OutputToSourceMap::iterator o = this->OutputToSource.find(name);
+ if (o != this->OutputToSource.end())
+ {
+ return (*o).second;
+ }
+ return 0;
+}
+
#if defined(CMAKE_BUILD_WITH_CMAKE)
cmSourceGroup* cmMakefile::GetSourceGroup(const std::vector<std::string>&name)
{