Skip to content

Commit 78ee2fb

Browse files
committed
Cleanup: llvm::bsearch -> llvm::partition_point after r364719
llvm-svn: 364720
1 parent 2d2cb77 commit 78ee2fb

File tree

22 files changed

+79
-82
lines changed

22 files changed

+79
-82
lines changed

clang-tools-extra/clangd/index/Symbol.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ float quality(const Symbol &S) {
3535
}
3636

3737
SymbolSlab::const_iterator SymbolSlab::find(const SymbolID &ID) const {
38-
auto It =
39-
llvm::bsearch(Symbols, [&](const Symbol &S) { return !(S.ID < ID); });
38+
auto It = llvm::partition_point(Symbols,
39+
[&](const Symbol &S) { return S.ID < ID; });
4040
if (It != Symbols.end() && It->ID == ID)
4141
return It;
4242
return Symbols.end();

clang/lib/Tooling/Syntax/Tokens.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ TokenBuffer::spelledForExpandedToken(const syntax::Token *Expanded) const {
127127

128128
unsigned ExpandedIndex = Expanded - ExpandedTokens.data();
129129
// Find the first mapping that produced tokens after \p Expanded.
130-
auto It = llvm::bsearch(File.Mappings, [&](const Mapping &M) {
131-
return ExpandedIndex < M.BeginExpanded;
130+
auto It = llvm::partition_point(File.Mappings, [&](const Mapping &M) {
131+
return M.BeginExpanded <= ExpandedIndex;
132132
});
133133
// Our token could only be produced by the previous mapping.
134134
if (It == File.Mappings.begin()) {
@@ -212,8 +212,8 @@ TokenBuffer::expansionStartingAt(const syntax::Token *Spelled) const {
212212
Spelled < (File.SpelledTokens.data() + File.SpelledTokens.size()));
213213

214214
unsigned SpelledIndex = Spelled - File.SpelledTokens.data();
215-
auto M = llvm::bsearch(File.Mappings, [&](const Mapping &M) {
216-
return SpelledIndex <= M.BeginSpelled;
215+
auto M = llvm::partition_point(File.Mappings, [&](const Mapping &M) {
216+
return M.BeginSpelled < SpelledIndex;
217217
});
218218
if (M == File.Mappings.end() || M->BeginSpelled != SpelledIndex)
219219
return llvm::None;

lld/ELF/DWARF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Optional<RelocAddrEntry>
8282
LLDDwarfObj<ELFT>::findAux(const InputSectionBase &Sec, uint64_t Pos,
8383
ArrayRef<RelTy> Rels) const {
8484
auto It =
85-
llvm::bsearch(Rels, [=](const RelTy &A) { return Pos <= A.r_offset; });
85+
partition_point(Rels, [=](const RelTy &A) { return A.r_offset < Pos; });
8686
if (It == Rels.end() || It->r_offset != Pos)
8787
return None;
8888
const RelTy &Rel = *It;

lld/ELF/InputSection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,8 +1268,8 @@ SectionPiece *MergeInputSection::getSectionPiece(uint64_t Offset) {
12681268

12691269
// If Offset is not at beginning of a section piece, it is not in the map.
12701270
// In that case we need to do a binary search of the original section piece vector.
1271-
auto It = llvm::bsearch(Pieces,
1272-
[=](SectionPiece P) { return Offset < P.InputOff; });
1271+
auto It = partition_point(
1272+
Pieces, [=](SectionPiece P) { return P.InputOff <= Offset; });
12731273
return &It[-1];
12741274
}
12751275

llvm/include/llvm/ADT/STLExtras.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,13 +1322,12 @@ void stable_sort(R &&Range, Compare C) {
13221322
std::stable_sort(adl_begin(Range), adl_end(Range), C);
13231323
}
13241324

1325-
/// Binary search for the first iterator in a range where a predicate is true.
1326-
/// Requires that C is always false below some limit, and always true above it.
1325+
/// Binary search for the first iterator in a range where a predicate is false.
1326+
/// Requires that C is always true below some limit, and always false above it.
13271327
template <typename R, typename Predicate,
13281328
typename Val = decltype(*adl_begin(std::declval<R>()))>
1329-
auto bsearch(R &&Range, Predicate P) -> decltype(adl_begin(Range)) {
1330-
return std::partition_point(adl_begin(Range), adl_end(Range),
1331-
[&](const Val &V) { return !P(V); });
1329+
auto partition_point(R &&Range, Predicate P) -> decltype(adl_begin(Range)) {
1330+
return std::partition_point(adl_begin(Range), adl_end(Range), P);
13321331
}
13331332

13341333
/// Wrapper function around std::equal to detect if all elements

llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,10 @@ class DWARFUnit {
473473
DWARFDie getDIEForOffset(uint32_t Offset) {
474474
extractDIEsIfNeeded(false);
475475
assert(!DieArray.empty());
476-
auto It = llvm::bsearch(DieArray, [=](const DWARFDebugInfoEntry &LHS) {
477-
return Offset <= LHS.getOffset();
478-
});
476+
auto It =
477+
llvm::partition_point(DieArray, [=](const DWARFDebugInfoEntry &DIE) {
478+
return DIE.getOffset() < Offset;
479+
});
479480
if (It != DieArray.end() && It->getOffset() == Offset)
480481
return DWARFDie(this, &*It);
481482
return DWARFDie();

llvm/lib/Analysis/ProfileSummaryInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ static cl::opt<int> ProfileSummaryColdCount(
6060
// Find the summary entry for a desired percentile of counts.
6161
static const ProfileSummaryEntry &getEntryForPercentile(SummaryEntryVector &DS,
6262
uint64_t Percentile) {
63-
auto It = llvm::bsearch(DS, [=](const ProfileSummaryEntry &Entry) {
64-
return Percentile <= Entry.Cutoff;
63+
auto It = partition_point(DS, [=](const ProfileSummaryEntry &Entry) {
64+
return Entry.Cutoff < Percentile;
6565
});
6666
// The required percentile has to be <= one of the percentiles in the
6767
// detailed summary.

llvm/lib/CodeGen/ExecutionDomainFix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ void ExecutionDomainFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
337337
// Sorted insertion.
338338
// Enables giving priority to the latest domains during merging.
339339
const int Def = RDA->getReachingDef(mi, RC->getRegister(rx));
340-
auto I = llvm::bsearch(Regs, [&](int I) {
341-
return Def < RDA->getReachingDef(mi, RC->getRegister(I));
340+
auto I = partition_point(Regs, [&](int I) {
341+
return RDA->getReachingDef(mi, RC->getRegister(I)) <= Def;
342342
});
343343
Regs.insert(I, rx);
344344
}

llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,10 @@ LegalizerInfo::findAction(const SizeAndActionsVec &Vec, const uint32_t Size) {
544544
// Find the last element in Vec that has a bitsize equal to or smaller than
545545
// the requested bit size.
546546
// That is the element just before the first element that is bigger than Size.
547-
auto VecIt = llvm::bsearch(
548-
Vec, [=](const SizeAndAction &A) { return Size < A.first; });
549-
assert(VecIt != Vec.begin() && "Does Vec not start with size 1?");
550-
--VecIt;
551-
int VecIdx = VecIt - Vec.begin();
547+
auto It = partition_point(
548+
Vec, [=](const SizeAndAction &A) { return A.first <= Size; });
549+
assert(It != Vec.begin() && "Does Vec not start with size 1?");
550+
int VecIdx = It - Vec.begin() - 1;
552551

553552
LegalizeAction Action = Vec[VecIdx].second;
554553
switch (Action) {

llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void DWARFDebugAranges::construct() {
115115

116116
uint32_t DWARFDebugAranges::findAddress(uint64_t Address) const {
117117
RangeCollIterator It =
118-
llvm::bsearch(Aranges, [=](Range RHS) { return Address < RHS.HighPC(); });
118+
partition_point(Aranges, [=](Range R) { return R.HighPC() <= Address; });
119119
if (It != Aranges.end() && It->LowPC <= Address)
120120
return It->CUOffset;
121121
return -1U;

0 commit comments

Comments
 (0)