From 864e2670d68324e44db076de68dee8b370fce22c Mon Sep 17 00:00:00 2001 From: Alexander Neundorf Date: Sat, 19 Sep 2009 13:02:12 -0400 Subject: Minor optimization in dependency checking. When reading the depend.internal file, check only once for every depender whether it exists, instead of repeatedly in a loop for each dependee. Within that function it can only change of the depender is removed. This is taken care of. This reduces the number of access() calls in kdelibs/khtml from 180000 to 90000 (i.e. 50%), and reduces the time for that (without the actual scanning) from 0.3 s to 0.21 s on my system. Alex --- Source/cmDepends.cxx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Source/cmDepends.cxx b/Source/cmDepends.cxx index 2cb1238..40e9730 100644 --- a/Source/cmDepends.cxx +++ b/Source/cmDepends.cxx @@ -152,6 +152,7 @@ bool cmDepends::CheckDependencies(std::istream& internalDepends) // or newer than the depender then dependencies should be // regenerated. bool okay = true; + bool dependerExists = false; while(internalDepends.getline(this->Dependee, this->MaxPath)) { if ( this->Dependee[0] == 0 || this->Dependee[0] == '#' || @@ -168,6 +169,11 @@ bool cmDepends::CheckDependencies(std::istream& internalDepends) if ( this->Dependee[0] != ' ' ) { memcpy(this->Depender, this->Dependee, len+1); + // Calling FileExists() for the depender here saves in many cases 50% + // of the calls to FileExists() further down in the loop. E.g. for + // 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); continue; } /* @@ -198,7 +204,7 @@ bool cmDepends::CheckDependencies(std::istream& internalDepends) cmSystemTools::Stdout(msg.str().c_str()); } } - else if(cmSystemTools::FileExists(depender)) + else if(dependerExists) { // The dependee and depender both exist. Compare file times. int result = 0; @@ -225,7 +231,11 @@ bool cmDepends::CheckDependencies(std::istream& internalDepends) okay = false; // Remove the depender to be sure it is rebuilt. - cmSystemTools::RemoveFile(depender); + if (dependerExists) + { + cmSystemTools::RemoveFile(depender); + dependerExists = false; + } } } -- cgit v0.12