diff options
author | Alexander Neundorf <neundorf@kde.org> | 2009-09-23 18:02:05 (GMT) |
---|---|---|
committer | Alexander Neundorf <neundorf@kde.org> | 2009-09-23 18:02:05 (GMT) |
commit | 39383ef8cb691656012275721064baef1e4f7511 (patch) | |
tree | 8d16274bd2092a6abe925bc7756c8a23594fd4b6 /Source/cmDepends.cxx | |
parent | 551fcc23c220fd75eaeea7671f28e8360e466b75 (diff) | |
download | CMake-39383ef8cb691656012275721064baef1e4f7511.zip CMake-39383ef8cb691656012275721064baef1e4f7511.tar.gz CMake-39383ef8cb691656012275721064baef1e4f7511.tar.bz2 |
Major optimization of C/C++ dependency scanning.
Now only the dependencies for the file where the dependencies actually may
have changed are rescanned, before that this was done for all source files
even if only one source file had changed.
This reduces e.g. on my machine the time for scanning the dependencies
of kdelibs/khtml/ when only one file (khtml_global.cpp) has changed from
around 7.5 seconds to 1.2 seconds.
The tests succeed, it does what I expected it to do on kdelibs, and Brad
also reviewed the patch, so I think it should be ok.
Alex
Diffstat (limited to 'Source/cmDepends.cxx')
-rw-r--r-- | Source/cmDepends.cxx | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/Source/cmDepends.cxx b/Source/cmDepends.cxx index 40e9730..72199fc 100644 --- a/Source/cmDepends.cxx +++ b/Source/cmDepends.cxx @@ -87,7 +87,8 @@ bool cmDepends::Finalize(std::ostream&, } //---------------------------------------------------------------------------- -bool cmDepends::Check(const char *makeFile, const char *internalFile) +bool cmDepends::Check(const char *makeFile, const char *internalFile, + std::map<std::string, DependencyVector>& validDeps) { // Dependency checks must be done in proper working directory. std::string oldcwd = "."; @@ -102,7 +103,7 @@ bool cmDepends::Check(const char *makeFile, const char *internalFile) // Check whether dependencies must be regenerated. bool okay = true; std::ifstream fin(internalFile); - if(!(fin && this->CheckDependencies(fin))) + if(!(fin && this->CheckDependencies(fin, validDeps))) { // Clear all dependencies so they will be regenerated. this->Clear(makeFile); @@ -146,13 +147,16 @@ bool cmDepends::WriteDependencies(const char*, const char*, } //---------------------------------------------------------------------------- -bool cmDepends::CheckDependencies(std::istream& internalDepends) +bool cmDepends::CheckDependencies(std::istream& internalDepends, + std::map<std::string, DependencyVector>& validDeps) { // Parse dependencies from the stream. If any dependee is missing // or newer than the depender then dependencies should be // regenerated. bool okay = true; bool dependerExists = false; + DependencyVector* currentDependencies = 0; + while(internalDepends.getline(this->Dependee, this->MaxPath)) { if ( this->Dependee[0] == 0 || this->Dependee[0] == '#' || @@ -174,6 +178,9 @@ bool cmDepends::CheckDependencies(std::istream& internalDepends) // kdelibs/khtml this reduces the number of calls from 184k down to 92k, // or the time for cmake -E cmake_depends from 0.3 s down to 0.21 s. dependerExists = cmSystemTools::FileExists(this->Depender); + DependencyVector tmp; + validDeps[this->Depender] = tmp; + currentDependencies = &validDeps[this->Depender]; continue; } /* @@ -189,6 +196,11 @@ bool cmDepends::CheckDependencies(std::istream& internalDepends) bool regenerate = false; const char* dependee = this->Dependee+1; const char* depender = this->Depender; + if (currentDependencies != 0) + { + currentDependencies->push_back(dependee); + } + if(!cmSystemTools::FileExists(dependee)) { // The dependee does not exist. @@ -230,6 +242,14 @@ bool cmDepends::CheckDependencies(std::istream& internalDepends) // Dependencies must be regenerated. okay = false; + // Remove the information of this depender from the map, it needs + // to be rescanned + if (currentDependencies != 0) + { + validDeps.erase(this->Depender); + currentDependencies = 0; + } + // Remove the depender to be sure it is rebuilt. if (dependerExists) { |