diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp --- a/bolt/lib/Core/BinaryContext.cpp +++ b/bolt/lib/Core/BinaryContext.cpp @@ -1961,12 +1961,11 @@ void BinaryContext::deregisterSectionName(const BinarySection &Section) { auto NameRange = NameToSection.equal_range(Section.getName().str()); - while (NameRange.first != NameRange.second) { - if (NameRange.first->second == &Section) { - NameToSection.erase(NameRange.first); + for (auto NSI : make_range(NameRange)) { + if (NSI.second == &Section) { + NameToSection.erase(NSI.first); break; } - ++NameRange.first; } } @@ -1993,12 +1992,11 @@ auto Itr = Sections.find(SectionPtr); if (Itr != Sections.end()) { auto Range = AddressToSection.equal_range(SectionPtr->getAddress()); - while (Range.first != Range.second) { - if (Range.first->second == SectionPtr) { - AddressToSection.erase(Range.first); + for (auto RI : make_range(Range)) { + if (RI.second == SectionPtr) { + AddressToSection.erase(RI.first); break; } - ++Range.first; } deregisterSectionName(*SectionPtr); diff --git a/bolt/lib/Profile/DataAggregator.cpp b/bolt/lib/Profile/DataAggregator.cpp --- a/bolt/lib/Profile/DataAggregator.cpp +++ b/bolt/lib/Profile/DataAggregator.cpp @@ -1999,14 +1999,11 @@ continue; // Consider only the first mapping of the file for any given PID - bool PIDExists = false; auto Range = GlobalMMapInfo.equal_range(FileMMapInfo.first); - for (auto MI = Range.first; MI != Range.second; ++MI) { - if (MI->second.PID == FileMMapInfo.second.PID) { - PIDExists = true; - break; - } - } + bool PIDExists = llvm::any_of(make_range(Range), [&](const auto &MI) { + return MI.second.PID == FileMMapInfo.second.PID; + }); + if (PIDExists) continue; @@ -2030,8 +2027,7 @@ } auto Range = GlobalMMapInfo.equal_range(NameToUse); - for (auto I = Range.first; I != Range.second; ++I) { - MMapInfo &MMapInfo = I->second; + for (MMapInfo &MMapInfo : make_second_range(make_range(Range))) { if (BC->HasFixedLoadAddress && MMapInfo.MMapAddress) { // Check that the binary mapping matches one of the segments. bool MatchFound = llvm::any_of( diff --git a/bolt/lib/Profile/DataReader.cpp b/bolt/lib/Profile/DataReader.cpp --- a/bolt/lib/Profile/DataReader.cpp +++ b/bolt/lib/Profile/DataReader.cpp @@ -215,9 +215,9 @@ } }; auto Range = std::equal_range(Data.begin(), Data.end(), From, Compare()); - for (auto I = Range.first; I != Range.second; ++I) - if (I->From.Name != I->To.Name) - return *I; + for (const auto &RI : llvm::make_range(Range)) + if (RI.From.Name != RI.To.Name) + return RI; return make_error_code(llvm::errc::invalid_argument); }