소스 검색

ENH: some performance optimizations

Ken Martin 19 년 전
부모
커밋
535acdc7a0
5개의 변경된 파일38개의 추가작업 그리고 16개의 파일을 삭제
  1. 17 5
      Source/cmGlobalGenerator.cxx
  2. 6 0
      Source/cmGlobalGenerator.h
  3. 2 3
      Source/cmLocalUnixMakefileGenerator3.cxx
  4. 12 8
      Source/cmMakefile.cxx
  5. 1 0
      Source/cmMakefile.h

+ 17 - 5
Source/cmGlobalGenerator.cxx

@@ -584,7 +584,8 @@ void cmGlobalGenerator::Configure()
 
   // Setup relative path generation.
   this->ConfigureRelativePaths();
-
+  this->TotalTargets.clear();
+  
   // start with this directory
   cmLocalGenerator *lg = this->CreateLocalGenerator();
   this->LocalGenerators.push_back(lg);
@@ -1019,17 +1020,28 @@ cmTarget* cmGlobalGenerator::FindTarget(const char* project,
                                         const char* name)
 {
   std::vector<cmLocalGenerator*>* gens = &this->LocalGenerators;
+  // if project specific
   if(project)
     {
     gens = &this->ProjectMap[project];
+    for(unsigned int i = 0; i < gens->size(); ++i)
+      {
+      cmTarget* ret = (*gens)[i]->GetMakefile()->FindTarget(name);
+      if(ret)
+        {
+        return ret;
+        }
+      }
     }
-  for(unsigned int i = 0; i < gens->size(); ++i)
+  // if all projects/directories
+  else
     {
-    cmTarget* ret = (*gens)[i]->GetMakefile()->FindTarget(name);
-    if(ret)
+    std::map<cmStdString,cmTarget *>::iterator i = this->TotalTargets.find(name);
+    if (i == this->TotalTargets.end())
       {
-      return ret;
+      return 0;
       }
+    return i->second;
     }
   return 0;
 }

+ 6 - 0
Source/cmGlobalGenerator.h

@@ -175,6 +175,9 @@ public:
       configuration.  This is valid during generation only.  */
   cmTargetManifest const& GetTargetManifest() { return this->TargetManifest; }
 
+  void AddTarget(cmTargets::value_type &v) { 
+    this->TotalTargets.insert(std::pair<cmStdString,cmTarget *>(v.first,&v.second));};
+  
   /** Support for multiple custom command outputs.  */
   virtual void CheckMultipleOutputs(cmMakefile* mf, bool verbose);
 
@@ -233,6 +236,9 @@ private:
   // using relative paths is unsafe.
   std::string RelativePathTopSource;
   std::string RelativePathTopBinary;
+
+  // this is used to improve performance 
+  std::map<cmStdString,cmTarget *> TotalTargets;
 };
 
 #endif

+ 2 - 3
Source/cmLocalUnixMakefileGenerator3.cxx

@@ -709,10 +709,8 @@ cmLocalUnixMakefileGenerator3
 std::string
 cmLocalUnixMakefileGenerator3::GetRelativeTargetDirectory(cmTarget& target)
 {
-  std::string dir = this->Makefile->GetStartOutputDirectory();
-  dir += "/";
+  std::string dir = this->HomeRelativeOutputPath;
   dir += this->GetTargetDirectory(target);
-  dir = cmSystemTools::RelativePath(this->Makefile->GetHomeOutputDirectory(), dir.c_str());
   return this->Convert(dir.c_str(),NONE,MAKEFILE);
 }
 
@@ -907,6 +905,7 @@ cmLocalUnixMakefileGenerator3::AppendEcho(std::vector<std::string>& commands,
 
   // Echo one line at a time.
   std::string line;
+  line.reserve(200);
   for(const char* c = text;; ++c)
     {
     if(*c == '\n' || *c == '\0')

+ 12 - 8
Source/cmMakefile.cxx

@@ -774,7 +774,9 @@ void cmMakefile::AddUtilityCommand(const char* utilityName, bool all,
   target.GetPostBuildCommands().push_back(cc);
 
   // Add the target to the set of targets.
-  this->Targets.insert(cmTargets::value_type(utilityName, target));
+  cmTargets::iterator it = 
+    this->Targets.insert(cmTargets::value_type(utilityName,target)).first;
+  this->LocalGenerator->GetGlobalGenerator()->AddTarget(*it);
 }
 
 void cmMakefile::AddDefineFlag(const char* flag)
@@ -1152,7 +1154,9 @@ void cmMakefile::AddLibrary(const char* lname, int shared,
   target.GetSourceLists() = srcs;
   target.SetMakefile(this);
   this->AddGlobalLinkInformation(lname, target);
-  this->Targets.insert(cmTargets::value_type(lname,target));
+  cmTargets::iterator it = 
+    this->Targets.insert(cmTargets::value_type(lname,target)).first;
+  this->LocalGenerator->GetGlobalGenerator()->AddTarget(*it);
 }
 
 cmTarget* cmMakefile::AddExecutable(const char *exeName, 
@@ -1166,6 +1170,7 @@ cmTarget* cmMakefile::AddExecutable(const char *exeName,
   this->AddGlobalLinkInformation(exeName, target);
   cmTargets::iterator it = 
     this->Targets.insert(cmTargets::value_type(exeName,target)).first;
+  this->LocalGenerator->GetGlobalGenerator()->AddTarget(*it);
   return &it->second;
 }
 
@@ -2560,14 +2565,13 @@ bool cmMakefile::GetPropertyAsBool(const char* prop) const
 cmTarget* cmMakefile::FindTarget(const char* name)
 {
   cmTargets& tgts = this->GetTargets();
-  for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
+  
+  cmTargets::iterator i = tgts.find(name);
+  if (i == tgts.end())
     {
-    if(l->first == name)
-      {
-      return &l->second;
-      }
+    return 0;
     }
-  return 0;
+  return &i->second;
 }
 
 cmTest* cmMakefile::CreateTest(const char* testName)

+ 1 - 0
Source/cmMakefile.h

@@ -414,6 +414,7 @@ public:
 
   cmTarget* FindTarget(const char* name);
 
+
   /**
    * Get a list of include directories in the build.
    */