From 7b0834e9bbe614670552036b14c7556a3c76c9a9 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 19 Jun 2014 10:45:08 -0400 Subject: [PATCH] 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. --- Source/cmTarget.cxx | 55 ++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index c8b16905b..5bb15f5b8 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -144,8 +144,15 @@ public: CompileInfoMapType CompileInfoMap; // Cache link implementation computation from each configuration. + struct OptionalLinkImplementation: public cmTarget::LinkImplementation + { + OptionalLinkImplementation(): + LibrariesDone(false), LanguagesDone(false) {} + bool LibrariesDone; + bool LanguagesDone; + }; typedef std::map LinkImplMapType; + OptionalLinkImplementation> LinkImplMapType; LinkImplMapType LinkImplMap; typedef std::map LinkClosureMapType; @@ -6519,28 +6526,21 @@ cmTarget::GetLinkImplementation(const std::string& config) const return 0; } - // Lookup any existing link implementation for this configuration. + // Populate the link implementation for this configuration. TargetConfigPair key(this, cmSystemTools::UpperCase(config)); - - cmTargetInternals::LinkImplMapType::iterator - i = this->Internal->LinkImplMap.find(key); - if(i == this->Internal->LinkImplMap.end()) + cmTargetInternals::OptionalLinkImplementation& + impl = this->Internal->LinkImplMap[key]; + if(!impl.LibrariesDone) { - // Compute the link implementation for this configuration. - LinkImplementation impl; + impl.LibrariesDone = true; 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 &i->second; + return &impl; } //---------------------------------------------------------------------------- @@ -6561,23 +6561,16 @@ cmTarget::GetLinkImplementationLibrariesInternal(const std::string& config, return 0; } - // Lookup any existing link implementation for this configuration. + // Populate the link implementation libraries for this configuration. TargetConfigPair key(head, cmSystemTools::UpperCase(config)); - - cmTargetInternals::LinkImplMapType::iterator - i = this->Internal->LinkImplMap.find(key); - if(i == this->Internal->LinkImplMap.end()) + cmTargetInternals::OptionalLinkImplementation& + impl = this->Internal->LinkImplMap[key]; + if(!impl.LibrariesDone) { - // Compute the link implementation for this configuration. - LinkImplementation impl; - 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; + impl.LibrariesDone = true; + this->ComputeLinkImplementation(config, impl, this); } - - return &i->second; + return &impl; } //----------------------------------------------------------------------------