Commit af3fd6f2 authored by Aaron Orenstein's avatar Aaron Orenstein

Performance: Add an index to Change cmLocalGenerator::GeneratorTargets.

Add an index to Change cmLocalGenerator::GeneratorTargets for faster lookup by
name.

Also changed a bunch of uses of cmLocalGenerator::GetGeneratorTargets() to take
const references instead of copying the vector.

Represent generator targets as a map (name -> target) to make name lookups more
efficient instead of looping through the entire vector to find the desired one.
parent c47c011c
......@@ -161,7 +161,7 @@ void cmComputeTargetDepends::CollectTargets()
std::vector<cmLocalGenerator*> const& lgens =
this->GlobalGenerator->GetLocalGenerators();
for (unsigned int i = 0; i < lgens.size(); ++i) {
const std::vector<cmGeneratorTarget*> targets =
const std::vector<cmGeneratorTarget*>& targets =
lgens[i]->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin();
ti != targets.end(); ++ti) {
......
......@@ -296,8 +296,9 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
// and UTILITY targets
for (std::vector<cmLocalGenerator*>::const_iterator lg = lgs.begin();
lg != lgs.end(); lg++) {
std::vector<cmGeneratorTarget*> targets = (*lg)->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
const std::vector<cmGeneratorTarget*>& targets =
(*lg)->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin();
ti != targets.end(); ti++) {
std::string targetName = (*ti)->GetName();
switch ((*ti)->GetType()) {
......@@ -359,8 +360,9 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
for (std::vector<cmLocalGenerator*>::const_iterator lg = lgs.begin();
lg != lgs.end(); lg++) {
cmMakefile* makefile = (*lg)->GetMakefile();
std::vector<cmGeneratorTarget*> targets = (*lg)->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
const std::vector<cmGeneratorTarget*>& targets =
(*lg)->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin();
ti != targets.end(); ti++) {
switch ((*ti)->GetType()) {
case cmStateEnums::EXECUTABLE:
......
......@@ -292,8 +292,9 @@ void cmExtraCodeLiteGenerator::CreateNewProjectFile(
for (std::vector<cmLocalGenerator*>::const_iterator lg = lgs.begin();
lg != lgs.end(); lg++) {
cmMakefile* makefile = (*lg)->GetMakefile();
std::vector<cmGeneratorTarget*> targets = (*lg)->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
const std::vector<cmGeneratorTarget*>& targets =
(*lg)->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin();
ti != targets.end(); ti++) {
projectType = CollectSourceFiles(makefile, *ti, cFiles, otherFiles);
}
......
......@@ -475,7 +475,7 @@ void cmExtraEclipseCDT4Generator::CreateLinksForTargets(cmXMLWriter& xml)
this->GlobalGenerator->GetLocalGenerators().begin();
lgIt != this->GlobalGenerator->GetLocalGenerators().end(); ++lgIt) {
cmMakefile* makefile = (*lgIt)->GetMakefile();
const std::vector<cmGeneratorTarget*> targets =
const std::vector<cmGeneratorTarget*>& targets =
(*lgIt)->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin();
......@@ -853,8 +853,9 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
for (std::vector<cmLocalGenerator*>::const_iterator it =
this->GlobalGenerator->GetLocalGenerators().begin();
it != this->GlobalGenerator->GetLocalGenerators().end(); ++it) {
std::vector<cmGeneratorTarget*> targets = (*it)->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::iterator l = targets.begin();
const std::vector<cmGeneratorTarget*>& targets =
(*it)->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator l = targets.begin();
l != targets.end(); ++l) {
std::vector<std::string> includeDirs;
std::string config = mf->GetSafeDefinition("CMAKE_BUILD_TYPE");
......@@ -910,7 +911,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
for (std::vector<cmLocalGenerator*>::const_iterator it =
this->GlobalGenerator->GetLocalGenerators().begin();
it != this->GlobalGenerator->GetLocalGenerators().end(); ++it) {
const std::vector<cmGeneratorTarget*> targets =
const std::vector<cmGeneratorTarget*>& targets =
(*it)->GetGeneratorTargets();
std::string subdir = (*it)->ConvertToRelativePath(
this->HomeOutputDirectory, (*it)->GetCurrentBinaryDirectory());
......
......@@ -115,7 +115,7 @@ void cmExtraKateGenerator::WriteTargets(const cmLocalGenerator* lg,
for (std::vector<cmLocalGenerator*>::const_iterator it =
this->GlobalGenerator->GetLocalGenerators().begin();
it != this->GlobalGenerator->GetLocalGenerators().end(); ++it) {
const std::vector<cmGeneratorTarget*> targets =
const std::vector<cmGeneratorTarget*>& targets =
(*it)->GetGeneratorTargets();
std::string currentDir = (*it)->GetCurrentBinaryDirectory();
bool topLevel = (currentDir == (*it)->GetBinaryDirectory());
......
......@@ -185,8 +185,9 @@ void cmExtraSublimeTextGenerator::AppendAllTargets(
for (std::vector<cmLocalGenerator*>::const_iterator lg = lgs.begin();
lg != lgs.end(); lg++) {
cmMakefile* makefile = (*lg)->GetMakefile();
std::vector<cmGeneratorTarget*> targets = (*lg)->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
const std::vector<cmGeneratorTarget*>& targets =
(*lg)->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin();
ti != targets.end(); ti++) {
std::string targetName = (*ti)->GetName();
switch ((*ti)->GetType()) {
......
......@@ -2594,9 +2594,9 @@ void cmGlobalGenerator::GetTargetSets(TargetDependSet& projectTargets,
continue;
}
// Get the targets in the makefile
std::vector<cmGeneratorTarget*> tgts = (*i)->GetGeneratorTargets();
const std::vector<cmGeneratorTarget*>& tgts = (*i)->GetGeneratorTargets();
// loop over all the targets
for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin();
l != tgts.end(); ++l) {
cmGeneratorTarget* target = *l;
if (this->IsRootOnlyTarget(target) &&
......@@ -2789,9 +2789,9 @@ void cmGlobalGenerator::WriteSummary()
cmGeneratedFileStream fout(fname.c_str());
for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) {
std::vector<cmGeneratorTarget*> tgts =
const std::vector<cmGeneratorTarget*>& tgts =
this->LocalGenerators[i]->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::iterator it = tgts.begin();
for (std::vector<cmGeneratorTarget*>::const_iterator it = tgts.begin();
it != tgts.end(); ++it) {
if ((*it)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
......
......@@ -128,8 +128,9 @@ bool cmGlobalKdevelopGenerator::CreateFilelistFile(
}
// get all sources
std::vector<cmGeneratorTarget*> targets = (*it)->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
const std::vector<cmGeneratorTarget*>& targets =
(*it)->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin();
ti != targets.end(); ti++) {
std::vector<cmSourceFile*> sources;
cmGeneratorTarget* gt = *ti;
......
......@@ -382,8 +382,8 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefileLanguageRules(
for (unsigned int i = 0; i < lGenerators.size(); ++i) {
lg = static_cast<cmLocalUnixMakefileGenerator3*>(lGenerators[i]);
// for all of out targets
std::vector<cmGeneratorTarget*> tgts = lg->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
const std::vector<cmGeneratorTarget*>& tgts = lg->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin();
l != tgts.end(); l++) {
if (((*l)->GetType() == cmStateEnums::EXECUTABLE) ||
((*l)->GetType() == cmStateEnums::STATIC_LIBRARY) ||
......@@ -414,8 +414,8 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2(
// The directory-level rule should depend on the target-level rules
// for all targets in the directory.
std::vector<std::string> depends;
std::vector<cmGeneratorTarget*> targets = lg->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::iterator l = targets.begin();
const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator l = targets.begin();
l != targets.end(); ++l) {
cmGeneratorTarget* gtarget = *l;
int type = gtarget->GetType();
......@@ -547,8 +547,8 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules(
for (i = 0; i < this->LocalGenerators.size(); ++i) {
lg = static_cast<cmLocalUnixMakefileGenerator3*>(this->LocalGenerators[i]);
// for each target Generate the rule files for each target.
std::vector<cmGeneratorTarget*> targets = lg->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin();
t != targets.end(); ++t) {
cmGeneratorTarget* gtarget = *t;
// Don't emit the same rule twice (e.g. two targets with the same
......@@ -629,8 +629,8 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
depends.push_back("cmake_check_build_system");
// for each target Generate the rule files for each target.
std::vector<cmGeneratorTarget*> targets = lg->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin();
t != targets.end(); ++t) {
cmGeneratorTarget* gtarget = *t;
int type = gtarget->GetType();
......@@ -807,7 +807,7 @@ void cmGlobalUnixMakefileGenerator3::InitializeProgressMarks()
this->LocalGenerators.begin();
lgi != this->LocalGenerators.end(); ++lgi) {
cmLocalGenerator* lg = *lgi;
std::vector<cmGeneratorTarget*> targets = lg->GetGeneratorTargets();
const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin();
t != targets.end(); ++t) {
cmGeneratorTarget* gt = *t;
......@@ -952,8 +952,9 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule(
// the targets
if (lg2 == lg || lg->IsRootMakefile()) {
// for each target Generate the rule files for each target.
std::vector<cmGeneratorTarget*> targets = lg2->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
const std::vector<cmGeneratorTarget*>& targets =
lg2->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin();
t != targets.end(); ++t) {
cmGeneratorTarget* target = *t;
cmStateEnums::TargetType type = target->GetType();
......
......@@ -420,7 +420,8 @@ int cmGraphVizWriter::CollectAllTargets()
for (std::vector<cmLocalGenerator*>::const_iterator lit =
this->LocalGenerators.begin();
lit != this->LocalGenerators.end(); ++lit) {
std::vector<cmGeneratorTarget*> targets = (*lit)->GetGeneratorTargets();
const std::vector<cmGeneratorTarget*>& targets =
(*lit)->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator it = targets.begin();
it != targets.end(); ++it) {
const char* realTargetName = (*it)->GetName().c_str();
......@@ -445,7 +446,8 @@ int cmGraphVizWriter::CollectAllExternalLibs(int cnt)
for (std::vector<cmLocalGenerator*>::const_iterator lit =
this->LocalGenerators.begin();
lit != this->LocalGenerators.end(); ++lit) {
std::vector<cmGeneratorTarget*> targets = (*lit)->GetGeneratorTargets();
const std::vector<cmGeneratorTarget*>& targets =
(*lit)->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator it = targets.begin();
it != targets.end(); ++it) {
const char* realTargetName = (*it)->GetName().c_str();
......
......@@ -214,8 +214,8 @@ void cmLocalGenerator::TraceDependencies()
this->GlobalGenerator->CreateEvaluationSourceFiles(*ci);
}
// Generate the rule files for each target.
std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin();
t != targets.end(); ++t) {
if ((*t)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
......@@ -548,6 +548,8 @@ void cmLocalGenerator::GenerateInstallRules()
void cmLocalGenerator::AddGeneratorTarget(cmGeneratorTarget* gt)
{
this->GeneratorTargets.push_back(gt);
this->GeneratorTargetSearchIndex.insert(
std::pair<std::string, cmGeneratorTarget*>(gt->GetName(), gt));
this->GlobalGenerator->IndexGeneratorTarget(gt);
}
......@@ -581,11 +583,10 @@ private:
cmGeneratorTarget* cmLocalGenerator::FindLocalNonAliasGeneratorTarget(
const std::string& name) const
{
std::vector<cmGeneratorTarget*>::const_iterator ti =
std::find_if(this->GeneratorTargets.begin(), this->GeneratorTargets.end(),
NamedGeneratorTargetFinder(name));
if (ti != this->GeneratorTargets.end()) {
return *ti;
GeneratorTargetMap::const_iterator ti =
this->GeneratorTargetSearchIndex.find(name);
if (ti != this->GeneratorTargetSearchIndex.end()) {
return ti->second;
}
return CM_NULLPTR;
}
......@@ -600,8 +601,8 @@ void cmLocalGenerator::ComputeTargetManifest()
}
// Add our targets to the manifest for each configuration.
std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin();
t != targets.end(); ++t) {
cmGeneratorTarget* target = *t;
if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
......@@ -625,8 +626,8 @@ bool cmLocalGenerator::ComputeTargetCompileFeatures()
}
// Process compile features of all targets.
std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin();
t != targets.end(); ++t) {
cmGeneratorTarget* target = *t;
for (std::vector<std::string>::iterator ci = configNames.begin();
......@@ -2121,8 +2122,8 @@ void cmLocalGenerator::GenerateTargetInstallRules(
{
// Convert the old-style install specification from each target to
// an install generator and run it.
std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
const std::vector<cmGeneratorTarget*>& tgts = this->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator l = tgts.begin();
l != tgts.end(); ++l) {
if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
......
......@@ -16,6 +16,7 @@
#include "cmOutputConverter.h"
#include "cmPolicies.h"
#include "cmStateSnapshot.h"
#include "cm_unordered_map.hxx"
#include "cmake.h"
class cmComputeLinkInformation;
......@@ -353,8 +354,11 @@ protected:
std::string::size_type ObjectPathMax;
std::set<std::string> ObjectMaxPathViolations;
std::set<cmGeneratorTarget const*> WarnCMP0063;
typedef CM_UNORDERED_MAP<std::string, cmGeneratorTarget*> GeneratorTargetMap;
GeneratorTargetMap GeneratorTargetSearchIndex;
std::vector<cmGeneratorTarget*> GeneratorTargets;
std::set<cmGeneratorTarget const*> WarnCMP0063;
std::vector<cmGeneratorTarget*> ImportedGeneratorTargets;
std::vector<cmGeneratorTarget*> OwnedImportedGeneratorTargets;
std::map<std::string, std::string> AliasTargets;
......
......@@ -79,8 +79,8 @@ void cmLocalNinjaGenerator::Generate()
}
}
std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin();
t != targets.end(); ++t) {
if ((*t)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
......
......@@ -116,10 +116,10 @@ void cmLocalUnixMakefileGenerator3::Generate()
this->Makefile->IsOn("CMAKE_SKIP_ASSEMBLY_SOURCE_RULES");
// Generate the rule files for each target.
std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets();
cmGlobalUnixMakefileGenerator3* gg =
static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin();
t != targets.end(); ++t) {
if ((*t)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
......@@ -172,8 +172,8 @@ void cmLocalUnixMakefileGenerator3::ComputeObjectFilenames(
void cmLocalUnixMakefileGenerator3::GetLocalObjectFiles(
std::map<std::string, LocalObjectInfo>& localObjectFiles)
{
std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets();
for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin();
ti != targets.end(); ++ti) {
cmGeneratorTarget* gt = *ti;
if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
......@@ -382,9 +382,9 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefileTargets(
// for each target we just provide a rule to cd up to the top and do a make
// on the target
std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets();
std::string localName;
for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin();
t != targets.end(); ++t) {
if (((*t)->GetType() == cmStateEnums::EXECUTABLE) ||
((*t)->GetType() == cmStateEnums::STATIC_LIBRARY) ||
......@@ -1562,8 +1562,8 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules(
this->WriteDivider(ruleFileStream);
ruleFileStream << "# Targets provided globally by CMake.\n"
<< "\n";
std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
std::vector<cmGeneratorTarget*>::iterator glIt;
const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets();
std::vector<cmGeneratorTarget*>::const_iterator glIt;
for (glIt = targets.begin(); glIt != targets.end(); ++glIt) {
if ((*glIt)->GetType() == cmStateEnums::GLOBAL_TARGET) {
std::string targetString =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment