From 2418a5aec0cad5cfd23fdb82ac6e11aa2a20a63e Mon Sep 17 00:00:00 2001 From: Leonid Pospelov Date: Fri, 12 Apr 2019 18:19:58 +0300 Subject: cmVisualStudio10TargetGenerator: Remove uses of const_cast --- Source/cmVisualStudio10TargetGenerator.cxx | 20 +++++++++----------- Source/cmVisualStudio10TargetGenerator.h | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 5195957..1b72ac3 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -1449,7 +1449,7 @@ void cmVisualStudio10TargetGenerator::WriteGroups() std::vector const& sources = this->GeneratorTarget->GetAllConfigSources(); - std::set groupsUsed; + std::set groupsUsed; for (cmGeneratorTarget::AllConfigSource const& si : sources) { std::string const& source = si.Source->GetFullPath(); cmSourceGroup* sourceGroup = @@ -1534,13 +1534,13 @@ void cmVisualStudio10TargetGenerator::WriteGroups() { Elem e1(e0, "ItemGroup"); e1.SetHasElements(); - std::vector groupsVec(groupsUsed.begin(), - groupsUsed.end()); + std::vector groupsVec(groupsUsed.begin(), + groupsUsed.end()); std::sort(groupsVec.begin(), groupsVec.end(), - [](cmSourceGroup* l, cmSourceGroup* r) { + [](cmSourceGroup const* l, cmSourceGroup const* r) { return l->GetFullName() < r->GetFullName(); }); - for (cmSourceGroup* sg : groupsVec) { + for (cmSourceGroup const* sg : groupsVec) { std::string const& name = sg->GetFullName(); if (!name.empty()) { std::string guidName = "SG_Filter_" + name; @@ -1572,7 +1572,7 @@ void cmVisualStudio10TargetGenerator::WriteGroups() // Add to groupsUsed empty source groups that have non-empty children. void cmVisualStudio10TargetGenerator::AddMissingSourceGroups( - std::set& groupsUsed, + std::set& groupsUsed, const std::vector& allGroups) { for (cmSourceGroup const& current : allGroups) { @@ -1583,8 +1583,7 @@ void cmVisualStudio10TargetGenerator::AddMissingSourceGroups( this->AddMissingSourceGroups(groupsUsed, children); - cmSourceGroup* current_ptr = const_cast(¤t); - if (groupsUsed.find(current_ptr) != groupsUsed.end()) { + if (groupsUsed.find(¤t) != groupsUsed.end()) { continue; // group has already been added to set } @@ -1592,8 +1591,7 @@ void cmVisualStudio10TargetGenerator::AddMissingSourceGroups( // (at least one child must already have been added) std::vector::const_iterator child_it = children.begin(); while (child_it != children.end()) { - cmSourceGroup* child_ptr = const_cast(&(*child_it)); - if (groupsUsed.find(child_ptr) != groupsUsed.end()) { + if (groupsUsed.find(&(*child_it)) != groupsUsed.end()) { break; // found a child that was already added => add current group too } child_it++; @@ -1603,7 +1601,7 @@ void cmVisualStudio10TargetGenerator::AddMissingSourceGroups( continue; // no descendants have source files => ignore this group } - groupsUsed.insert(current_ptr); + groupsUsed.insert(¤t); } } diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index 5901004..6a1ee1d 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -165,7 +165,7 @@ private: void WriteGroupSources(Elem& e0, std::string const& name, ToolSources const& sources, std::vector&); - void AddMissingSourceGroups(std::set& groupsUsed, + void AddMissingSourceGroups(std::set& groupsUsed, const std::vector& allGroups); bool IsResxHeader(const std::string& headerFile); bool IsXamlHeader(const std::string& headerFile); -- cgit v0.12 From e10b04ef055f2c46749e683d13b643c9e2cf32e7 Mon Sep 17 00:00:00 2001 From: Leonid Pospelov Date: Fri, 12 Apr 2019 18:21:55 +0300 Subject: cmVisualStudio10TargetGenerator: Use count instead of find --- Source/cmVisualStudio10TargetGenerator.cxx | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 1b72ac3..80b1add 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -1583,15 +1583,15 @@ void cmVisualStudio10TargetGenerator::AddMissingSourceGroups( this->AddMissingSourceGroups(groupsUsed, children); - if (groupsUsed.find(¤t) != groupsUsed.end()) { + if (groupsUsed.count(¤t) > 0) { continue; // group has already been added to set } // check if it least one of the group's descendants is not empty // (at least one child must already have been added) - std::vector::const_iterator child_it = children.begin(); + auto child_it = children.begin(); while (child_it != children.end()) { - if (groupsUsed.find(&(*child_it)) != groupsUsed.end()) { + if (groupsUsed.count(&(*child_it)) > 0) { break; // found a child that was already added => add current group too } child_it++; @@ -2528,10 +2528,9 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( } else { std::set languages; this->GeneratorTarget->GetLanguages(languages, configName); - for (const char* const* l = cm::cbegin(clLangs); l != cm::cend(clLangs); - ++l) { - if (languages.find(*l) != languages.end()) { - langForClCompile = *l; + for (const char* l : clLangs) { + if (languages.count(l)) { + langForClCompile = l; break; } } @@ -4056,10 +4055,7 @@ bool cmVisualStudio10TargetGenerator::IsResxHeader( { std::set expectedResxHeaders; this->GeneratorTarget->GetExpectedResxHeaders(expectedResxHeaders, ""); - - std::set::const_iterator it = - expectedResxHeaders.find(headerFile); - return it != expectedResxHeaders.end(); + return expectedResxHeaders.count(headerFile) > 0; } bool cmVisualStudio10TargetGenerator::IsXamlHeader( @@ -4067,10 +4063,7 @@ bool cmVisualStudio10TargetGenerator::IsXamlHeader( { std::set expectedXamlHeaders; this->GeneratorTarget->GetExpectedXamlHeaders(expectedXamlHeaders, ""); - - std::set::const_iterator it = - expectedXamlHeaders.find(headerFile); - return it != expectedXamlHeaders.end(); + return expectedXamlHeaders.count(headerFile) > 0; } bool cmVisualStudio10TargetGenerator::IsXamlSource( @@ -4078,10 +4071,7 @@ bool cmVisualStudio10TargetGenerator::IsXamlSource( { std::set expectedXamlSources; this->GeneratorTarget->GetExpectedXamlSources(expectedXamlSources, ""); - - std::set::const_iterator it = - expectedXamlSources.find(sourceFile); - return it != expectedXamlSources.end(); + return expectedXamlSources.count(sourceFile) > 0; } void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings(Elem& e1) -- cgit v0.12 From 3e70a8d0df08301e11fd5c01e623223e434b3d3c Mon Sep 17 00:00:00 2001 From: Leonid Pospelov Date: Fri, 12 Apr 2019 18:24:21 +0300 Subject: cmVisualStudio10TargetGenerator: Simplify code of two functions --- Source/cmVisualStudio10TargetGenerator.cxx | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 80b1add..0cec2fb 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -1430,10 +1430,10 @@ std::string cmVisualStudio10TargetGenerator::ConvertPath( static void ConvertToWindowsSlash(std::string& s) { // first convert all of the slashes - std::string::size_type pos = 0; - while ((pos = s.find('/', pos)) != std::string::npos) { - s[pos] = '\\'; - pos++; + for (auto& ch : s) { + if (ch == '/') { + ch = '\\'; + } } } @@ -4642,10 +4642,8 @@ void cmVisualStudio10TargetGenerator::GetCSharpSourceProperties( void cmVisualStudio10TargetGenerator::WriteCSharpSourceProperties( Elem& e2, const std::map& tags) { - if (!tags.empty()) { - for (const auto& i : tags) { - e2.Element(i.first.c_str(), i.second); - } + for (const auto& i : tags) { + e2.Element(i.first.c_str(), i.second); } } -- cgit v0.12