From 314c9ae33bfd304c9622b89ec62bca052f6e0d39 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 2 Aug 2015 09:11:55 +0200 Subject: [PATCH 1/4] cmLocalGenerator: Make GetFeature tail-recursive. --- Source/cmLocalGenerator.cxx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index edb644de7..169cdf46d 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2384,11 +2384,12 @@ const char* cmLocalGenerator::GetFeature(const std::string& feature, { return value; } - if(cmLocalGenerator* parent = this->GetParent()) + cmLocalGenerator* parent = this->GetParent(); + if(!parent) { - return parent->GetFeature(feature, config); + return 0; } - return 0; + return parent->GetFeature(feature, config); } //---------------------------------------------------------------------------- From ad0b0089ab9f094192f6109067d79ef5e66c85b7 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 2 Aug 2015 09:14:28 +0200 Subject: [PATCH 2/4] cmLocalGenerator: Simplify GetFeature implementation. --- Source/cmLocalGenerator.cxx | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 169cdf46d..2a88e3c83 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2368,19 +2368,15 @@ void cmLocalGenerator::AppendFeatureOptions( const char* cmLocalGenerator::GetFeature(const std::string& feature, const std::string& config) { + std::string featureName = feature; // TODO: Define accumulation policy for features (prepend, append, replace). // Currently we always replace. if(!config.empty()) { - std::string featureConfig = feature; - featureConfig += "_"; - featureConfig += cmSystemTools::UpperCase(config); - if(const char* value = this->Makefile->GetProperty(featureConfig)) - { - return value; - } + featureName += "_"; + featureName += cmSystemTools::UpperCase(config); } - if(const char* value = this->Makefile->GetProperty(feature)) + if(const char* value = this->Makefile->GetProperty(featureName)) { return value; } From 7441fde34abf5a3eab58917b8bf4acb89d72c00c Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 2 Aug 2015 09:16:17 +0200 Subject: [PATCH 3/4] cmLocalGenerator: Convert GetFeature recursion to loop. --- Source/cmLocalGenerator.cxx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 2a88e3c83..8e12eb6d0 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2376,16 +2376,16 @@ const char* cmLocalGenerator::GetFeature(const std::string& feature, featureName += "_"; featureName += cmSystemTools::UpperCase(config); } - if(const char* value = this->Makefile->GetProperty(featureName)) + cmLocalGenerator* lg = this; + while(lg) { - return value; + if(const char* value = lg->GetMakefile()->GetProperty(featureName)) + { + return value; + } + lg = lg->GetParent(); } - cmLocalGenerator* parent = this->GetParent(); - if(!parent) - { - return 0; - } - return parent->GetFeature(feature, config); + return 0; } //---------------------------------------------------------------------------- From e3078aa15328439e239b2beb4085dc644ec465ec Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 2 Aug 2015 09:18:37 +0200 Subject: [PATCH 4/4] cmLocalGenerator: Implement GetFeature in terms of cmState. --- Source/cmLocalGenerator.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 8e12eb6d0..c2d1a7d89 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2376,14 +2376,14 @@ const char* cmLocalGenerator::GetFeature(const std::string& feature, featureName += "_"; featureName += cmSystemTools::UpperCase(config); } - cmLocalGenerator* lg = this; - while(lg) + cmState::Snapshot snp = this->StateSnapshot; + while(snp.IsValid()) { - if(const char* value = lg->GetMakefile()->GetProperty(featureName)) + if(const char* value = snp.GetDirectory().GetProperty(featureName)) { return value; } - lg = lg->GetParent(); + snp = snp.GetBuildsystemDirectoryParent(); } return 0; }