cmTarget: Refactor internal LinkImplementation map

If ComputeLinkImplementationLanguages were ever to cause
GetLinkImplementationLibraries to be invoked then a LinkImplMap entry
may appear in the middle of computing it in GetLinkInformation.  Instead
create the map entry up front and store in it boolean values indicating
which pieces of the LinkImplementation structure have been populated.
This approach leads to shorter code that is easier to follow too.
This commit is contained in:
Brad King 2014-06-19 10:45:08 -04:00
parent b8651d970d
commit 7b0834e9bb
1 changed files with 24 additions and 31 deletions

View File

@ -144,8 +144,15 @@ public:
CompileInfoMapType CompileInfoMap; CompileInfoMapType CompileInfoMap;
// Cache link implementation computation from each configuration. // Cache link implementation computation from each configuration.
struct OptionalLinkImplementation: public cmTarget::LinkImplementation
{
OptionalLinkImplementation():
LibrariesDone(false), LanguagesDone(false) {}
bool LibrariesDone;
bool LanguagesDone;
};
typedef std::map<TargetConfigPair, typedef std::map<TargetConfigPair,
cmTarget::LinkImplementation> LinkImplMapType; OptionalLinkImplementation> LinkImplMapType;
LinkImplMapType LinkImplMap; LinkImplMapType LinkImplMap;
typedef std::map<std::string, cmTarget::LinkClosure> LinkClosureMapType; typedef std::map<std::string, cmTarget::LinkClosure> LinkClosureMapType;
@ -6519,28 +6526,21 @@ cmTarget::GetLinkImplementation(const std::string& config) const
return 0; return 0;
} }
// Lookup any existing link implementation for this configuration. // Populate the link implementation for this configuration.
TargetConfigPair key(this, cmSystemTools::UpperCase(config)); TargetConfigPair key(this, cmSystemTools::UpperCase(config));
cmTargetInternals::OptionalLinkImplementation&
cmTargetInternals::LinkImplMapType::iterator impl = this->Internal->LinkImplMap[key];
i = this->Internal->LinkImplMap.find(key); if(!impl.LibrariesDone)
if(i == this->Internal->LinkImplMap.end())
{ {
// Compute the link implementation for this configuration. impl.LibrariesDone = true;
LinkImplementation impl;
this->ComputeLinkImplementation(config, impl, this); this->ComputeLinkImplementation(config, impl, this);
this->ComputeLinkImplementationLanguages(config, impl, this);
// Store the information for this configuration.
cmTargetInternals::LinkImplMapType::value_type entry(key, impl);
i = this->Internal->LinkImplMap.insert(entry).first;
} }
else if (i->second.Languages.empty()) if(!impl.LanguagesDone)
{ {
this->ComputeLinkImplementationLanguages(config, i->second, this); impl.LanguagesDone = true;
this->ComputeLinkImplementationLanguages(config, impl, this);
} }
return &impl;
return &i->second;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -6561,23 +6561,16 @@ cmTarget::GetLinkImplementationLibrariesInternal(const std::string& config,
return 0; return 0;
} }
// Lookup any existing link implementation for this configuration. // Populate the link implementation libraries for this configuration.
TargetConfigPair key(head, cmSystemTools::UpperCase(config)); TargetConfigPair key(head, cmSystemTools::UpperCase(config));
cmTargetInternals::OptionalLinkImplementation&
cmTargetInternals::LinkImplMapType::iterator impl = this->Internal->LinkImplMap[key];
i = this->Internal->LinkImplMap.find(key); if(!impl.LibrariesDone)
if(i == this->Internal->LinkImplMap.end())
{ {
// Compute the link implementation for this configuration. impl.LibrariesDone = true;
LinkImplementation impl; this->ComputeLinkImplementation(config, impl, this);
this->ComputeLinkImplementation(config, impl, head);
// Store the information for this configuration.
cmTargetInternals::LinkImplMapType::value_type entry(key, impl);
i = this->Internal->LinkImplMap.insert(entry).first;
} }
return &impl;
return &i->second;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------