Skip to content

Commit b76b345

Browse files
committed
Change std::{lower,upper}_bound to llvm::{lower,upper}_bound or llvm::partition_point. NFC
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@365006 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 41b9480 commit b76b345

22 files changed

+58
-89
lines changed

include/clang/Serialization/ContinuousRangeMap.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ContinuousRangeMap {
7373
}
7474

7575
void insertOrReplace(const value_type &Val) {
76-
iterator I = std::lower_bound(Rep.begin(), Rep.end(), Val, Compare());
76+
iterator I = llvm::lower_bound(Rep, Val, Compare());
7777
if (I != Rep.end() && I->first == Val.first) {
7878
I->second = Val.second;
7979
return;
@@ -91,7 +91,7 @@ class ContinuousRangeMap {
9191
const_iterator end() const { return Rep.end(); }
9292

9393
iterator find(Int K) {
94-
iterator I = std::upper_bound(Rep.begin(), Rep.end(), K, Compare());
94+
iterator I = llvm::upper_bound(Rep, K, Compare());
9595
// I points to the first entry with a key > K, which is the range that
9696
// follows the one containing K.
9797
if (I == Rep.begin())

lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ static bool isEmptyARCMTMacroStatement(NullStmt *S,
4242
return false;
4343

4444
SourceManager &SM = Ctx.getSourceManager();
45-
std::vector<SourceLocation>::iterator
46-
I = std::upper_bound(MacroLocs.begin(), MacroLocs.end(), SemiLoc,
47-
BeforeThanCompare<SourceLocation>(SM));
45+
std::vector<SourceLocation>::iterator I = llvm::upper_bound(
46+
MacroLocs, SemiLoc, BeforeThanCompare<SourceLocation>(SM));
4847
--I;
4948
SourceLocation
5049
AfterMacroLoc = I->getLocWithOffset(getARCMTMacroName().size());

lib/AST/ASTContext.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,11 @@ RawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const {
228228

229229
if (Found) {
230230
Comment = MaybeBeforeDecl + 1;
231-
assert(Comment == std::lower_bound(RawComments.begin(), RawComments.end(),
232-
&CommentAtDeclLoc, Compare));
231+
assert(Comment ==
232+
llvm::lower_bound(RawComments, &CommentAtDeclLoc, Compare));
233233
} else {
234234
// Slow path.
235-
Comment = std::lower_bound(RawComments.begin(), RawComments.end(),
236-
&CommentAtDeclLoc, Compare);
235+
Comment = llvm::lower_bound(RawComments, &CommentAtDeclLoc, Compare);
237236
}
238237
}
239238

lib/AST/DeclCXX.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1450,10 +1450,8 @@ CXXRecordDecl::getLambdaExplicitTemplateParameters() const {
14501450
[](const NamedDecl *D) { return !D->isImplicit(); })
14511451
&& "Explicit template params should be ordered before implicit ones");
14521452

1453-
const auto ExplicitEnd = std::lower_bound(List->begin(), List->end(), false,
1454-
[](const NamedDecl *D, bool) {
1455-
return !D->isImplicit();
1456-
});
1453+
const auto ExplicitEnd = llvm::partition_point(
1454+
*List, [](const NamedDecl *D) { return !D->isImplicit(); });
14571455
return llvm::makeArrayRef(List->begin(), ExplicitEnd);
14581456
}
14591457

lib/Basic/Diagnostic.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,9 @@ DiagnosticsEngine::DiagStateMap::lookup(SourceManager &SrcMgr,
205205

206206
DiagnosticsEngine::DiagState *
207207
DiagnosticsEngine::DiagStateMap::File::lookup(unsigned Offset) const {
208-
auto OnePastIt = std::upper_bound(
209-
StateTransitions.begin(), StateTransitions.end(), Offset,
210-
[](unsigned Offset, const DiagStatePoint &P) {
211-
return Offset < P.Offset;
208+
auto OnePastIt =
209+
llvm::partition_point(StateTransitions, [=](const DiagStatePoint &P) {
210+
return P.Offset <= Offset;
212211
});
213212
assert(OnePastIt != StateTransitions.begin() && "missing initial state");
214213
return OnePastIt[-1].State;

lib/Basic/DiagnosticIDs.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -580,11 +580,8 @@ static bool getDiagnosticsInGroup(diag::Flavor Flavor,
580580
bool
581581
DiagnosticIDs::getDiagnosticsInGroup(diag::Flavor Flavor, StringRef Group,
582582
SmallVectorImpl<diag::kind> &Diags) const {
583-
auto Found = std::lower_bound(std::begin(OptionTable), std::end(OptionTable),
584-
Group,
585-
[](const WarningOption &LHS, StringRef RHS) {
586-
return LHS.getName() < RHS;
587-
});
583+
auto Found = llvm::partition_point(
584+
OptionTable, [=](const WarningOption &O) { return O.getName() < Group; });
588585
if (Found == std::end(OptionTable) || Found->getName() != Group)
589586
return true; // Option not found.
590587

lib/Basic/SourceManager.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ const LineEntry *LineTableInfo::FindNearestLineEntry(FileID FID,
277277
return &Entries.back();
278278

279279
// Do a binary search to find the maximal element that is still before Offset.
280-
std::vector<LineEntry>::const_iterator I =
281-
std::upper_bound(Entries.begin(), Entries.end(), Offset);
282-
if (I == Entries.begin()) return nullptr;
280+
std::vector<LineEntry>::const_iterator I = llvm::upper_bound(Entries, Offset);
281+
if (I == Entries.begin())
282+
return nullptr;
283283
return &*--I;
284284
}
285285

lib/CodeGen/CGBuiltin.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -5076,8 +5076,7 @@ findNeonIntrinsicInMap(ArrayRef<NeonIntrinsicInfo> IntrinsicMap,
50765076
}
50775077
#endif
50785078

5079-
const NeonIntrinsicInfo *Builtin =
5080-
std::lower_bound(IntrinsicMap.begin(), IntrinsicMap.end(), BuiltinID);
5079+
const NeonIntrinsicInfo *Builtin = llvm::lower_bound(IntrinsicMap, BuiltinID);
50815080

50825081
if (Builtin != IntrinsicMap.end() && Builtin->BuiltinID == BuiltinID)
50835082
return Builtin;

lib/CodeGen/CGExprConstant.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ Optional<size_t> ConstantAggregateBuilder::splitAt(CharUnits Pos) {
288288
return Offsets.size();
289289

290290
while (true) {
291-
auto FirstAfterPos = std::upper_bound(Offsets.begin(), Offsets.end(), Pos);
291+
auto FirstAfterPos = llvm::upper_bound(Offsets, Pos);
292292
if (FirstAfterPos == Offsets.begin())
293293
return 0;
294294

lib/Frontend/ASTUnit.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -2447,8 +2447,8 @@ void ASTUnit::addFileLevelDecl(Decl *D) {
24472447
return;
24482448
}
24492449

2450-
LocDeclsTy::iterator I = std::upper_bound(Decls->begin(), Decls->end(),
2451-
LocDecl, llvm::less_first());
2450+
LocDeclsTy::iterator I =
2451+
llvm::upper_bound(*Decls, LocDecl, llvm::less_first());
24522452

24532453
Decls->insert(I, LocDecl);
24542454
}
@@ -2473,9 +2473,9 @@ void ASTUnit::findFileRegionDecls(FileID File, unsigned Offset, unsigned Length,
24732473
return;
24742474

24752475
LocDeclsTy::iterator BeginIt =
2476-
std::lower_bound(LocDecls.begin(), LocDecls.end(),
2477-
std::make_pair(Offset, (Decl *)nullptr),
2478-
llvm::less_first());
2476+
llvm::partition_point(LocDecls, [=](std::pair<unsigned, Decl *> LD) {
2477+
return LD.first < Offset;
2478+
});
24792479
if (BeginIt != LocDecls.begin())
24802480
--BeginIt;
24812481

@@ -2486,9 +2486,9 @@ void ASTUnit::findFileRegionDecls(FileID File, unsigned Offset, unsigned Length,
24862486
BeginIt->second->isTopLevelDeclInObjCContainer())
24872487
--BeginIt;
24882488

2489-
LocDeclsTy::iterator EndIt = std::upper_bound(
2490-
LocDecls.begin(), LocDecls.end(),
2491-
std::make_pair(Offset + Length, (Decl *)nullptr), llvm::less_first());
2489+
LocDeclsTy::iterator EndIt = llvm::upper_bound(
2490+
LocDecls, std::make_pair(Offset + Length, (Decl *)nullptr),
2491+
llvm::less_first());
24922492
if (EndIt != LocDecls.end())
24932493
++EndIt;
24942494

lib/Index/FileIndexRecord.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void FileIndexRecord::addDeclOccurence(SymbolRoleSet Roles, unsigned Offset,
3636

3737
DeclOccurrence NewInfo(Roles, Offset, D, Relations);
3838
// We keep Decls in order as we need to access them in this order in all cases.
39-
auto It = std::upper_bound(Decls.begin(), Decls.end(), NewInfo);
39+
auto It = llvm::upper_bound(Decls, NewInfo);
4040
Decls.insert(It, std::move(NewInfo));
4141
}
4242

lib/Lex/PPConditionalDirectiveRecord.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ bool PPConditionalDirectiveRecord::rangeIntersectsConditionalDirective(
2525
if (Range.isInvalid())
2626
return false;
2727

28-
CondDirectiveLocsTy::const_iterator
29-
low = std::lower_bound(CondDirectiveLocs.begin(), CondDirectiveLocs.end(),
30-
Range.getBegin(), CondDirectiveLoc::Comp(SourceMgr));
28+
CondDirectiveLocsTy::const_iterator low = llvm::lower_bound(
29+
CondDirectiveLocs, Range.getBegin(), CondDirectiveLoc::Comp(SourceMgr));
3130
if (low == CondDirectiveLocs.end())
3231
return false;
3332

@@ -55,9 +54,8 @@ SourceLocation PPConditionalDirectiveRecord::findConditionalDirectiveRegionLoc(
5554
Loc))
5655
return CondDirectiveStack.back();
5756

58-
CondDirectiveLocsTy::const_iterator
59-
low = std::lower_bound(CondDirectiveLocs.begin(), CondDirectiveLocs.end(),
60-
Loc, CondDirectiveLoc::Comp(SourceMgr));
57+
CondDirectiveLocsTy::const_iterator low = llvm::lower_bound(
58+
CondDirectiveLocs, Loc, CondDirectiveLoc::Comp(SourceMgr));
6159
assert(low != CondDirectiveLocs.end());
6260
return low->getRegionLoc();
6361
}

lib/Lex/PreprocessingRecord.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,13 @@ unsigned PreprocessingRecord::findBeginLocalPreprocessedEntity(
238238
return First - PreprocessedEntities.begin();
239239
}
240240

241-
unsigned PreprocessingRecord::findEndLocalPreprocessedEntity(
242-
SourceLocation Loc) const {
241+
unsigned
242+
PreprocessingRecord::findEndLocalPreprocessedEntity(SourceLocation Loc) const {
243243
if (SourceMgr.isLoadedSourceLocation(Loc))
244244
return 0;
245245

246-
std::vector<PreprocessedEntity *>::const_iterator
247-
I = std::upper_bound(PreprocessedEntities.begin(),
248-
PreprocessedEntities.end(),
249-
Loc,
250-
PPEntityComp<&SourceRange::getBegin>(SourceMgr));
246+
auto I = llvm::upper_bound(PreprocessedEntities, Loc,
247+
PPEntityComp<&SourceRange::getBegin>(SourceMgr));
251248
return I - PreprocessedEntities.begin();
252249
}
253250

@@ -305,10 +302,9 @@ PreprocessingRecord::addPreprocessedEntity(PreprocessedEntity *Entity) {
305302
}
306303

307304
// Linear search unsuccessful. Do a binary search.
308-
pp_iter I = std::upper_bound(PreprocessedEntities.begin(),
309-
PreprocessedEntities.end(),
310-
BeginLoc,
311-
PPEntityComp<&SourceRange::getBegin>(SourceMgr));
305+
pp_iter I =
306+
llvm::upper_bound(PreprocessedEntities, BeginLoc,
307+
PPEntityComp<&SourceRange::getBegin>(SourceMgr));
312308
pp_iter insertI = PreprocessedEntities.insert(I, Entity);
313309
return getPPEntityID(insertI - PreprocessedEntities.begin(),
314310
/*isLoaded=*/false);

lib/Parse/ParseStmtAsm.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ void ClangAsmParserCallback::findTokensForString(
144144

145145
// Try to find a token whose offset matches the first token.
146146
unsigned FirstCharOffset = Str.begin() - AsmString.begin();
147-
const unsigned *FirstTokOffset = std::lower_bound(
148-
AsmTokOffsets.begin(), AsmTokOffsets.end(), FirstCharOffset);
147+
const unsigned *FirstTokOffset =
148+
llvm::lower_bound(AsmTokOffsets, FirstCharOffset);
149149

150150
// For now, assert that the start of the string exactly
151151
// corresponds to the start of a token.
@@ -174,8 +174,7 @@ ClangAsmParserCallback::translateLocation(const llvm::SourceMgr &LSM,
174174
unsigned Offset = SMLoc.getPointer() - LBuf->getBufferStart();
175175

176176
// Figure out which token that offset points into.
177-
const unsigned *TokOffsetPtr =
178-
std::lower_bound(AsmTokOffsets.begin(), AsmTokOffsets.end(), Offset);
177+
const unsigned *TokOffsetPtr = llvm::lower_bound(AsmTokOffsets, Offset);
179178
unsigned TokIndex = TokOffsetPtr - AsmTokOffsets.begin();
180179
unsigned TokOffset = *TokOffsetPtr;
181180

lib/Sema/SemaChecking.cpp

+4-9
Original file line numberDiff line numberDiff line change
@@ -2701,8 +2701,7 @@ bool Sema::CheckHexagonBuiltinCpu(unsigned BuiltinID, CallExpr *TheCall) {
27012701
const TargetInfo &TI = Context.getTargetInfo();
27022702

27032703
const BuiltinAndString *FC =
2704-
std::lower_bound(std::begin(ValidCPU), std::end(ValidCPU), BuiltinID,
2705-
LowerBoundCmp);
2704+
llvm::lower_bound(ValidCPU, BuiltinID, LowerBoundCmp);
27062705
if (FC != std::end(ValidCPU) && FC->BuiltinID == BuiltinID) {
27072706
const TargetOptions &Opts = TI.getTargetOpts();
27082707
StringRef CPU = Opts.CPU;
@@ -2718,8 +2717,7 @@ bool Sema::CheckHexagonBuiltinCpu(unsigned BuiltinID, CallExpr *TheCall) {
27182717
}
27192718

27202719
const BuiltinAndString *FH =
2721-
std::lower_bound(std::begin(ValidHVX), std::end(ValidHVX), BuiltinID,
2722-
LowerBoundCmp);
2720+
llvm::lower_bound(ValidHVX, BuiltinID, LowerBoundCmp);
27232721
if (FH != std::end(ValidHVX) && FH->BuiltinID == BuiltinID) {
27242722
if (!TI.hasFeature("hvx"))
27252723
return Diag(TheCall->getBeginLoc(),
@@ -2948,11 +2946,8 @@ bool Sema::CheckHexagonBuiltinArgument(unsigned BuiltinID, CallExpr *TheCall) {
29482946
true);
29492947
(void)SortOnce;
29502948

2951-
const BuiltinInfo *F =
2952-
std::lower_bound(std::begin(Infos), std::end(Infos), BuiltinID,
2953-
[](const BuiltinInfo &BI, unsigned BuiltinID) {
2954-
return BI.BuiltinID < BuiltinID;
2955-
});
2949+
const BuiltinInfo *F = llvm::partition_point(
2950+
Infos, [=](const BuiltinInfo &BI) { return BI.BuiltinID < BuiltinID; });
29562951
if (F == std::end(Infos) || F->BuiltinID != BuiltinID)
29572952
return false;
29582953

lib/Sema/SemaStmt.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -1041,9 +1041,8 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch,
10411041

10421042
// Find the smallest value >= the lower bound. If I is in the
10431043
// case range, then we have overlap.
1044-
CaseValsTy::iterator I = std::lower_bound(CaseVals.begin(),
1045-
CaseVals.end(), CRLo,
1046-
CaseCompareFunctor());
1044+
CaseValsTy::iterator I =
1045+
llvm::lower_bound(CaseVals, CRLo, CaseCompareFunctor());
10471046
if (I != CaseVals.end() && I->first < CRHi) {
10481047
OverlapVal = I->first; // Found overlap with scalar.
10491048
OverlapStmt = I->second;

lib/Serialization/ASTReader.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -7948,9 +7948,8 @@ void ASTReader::FindFileRegionDecls(FileID File,
79487948
SourceLocation EndLoc = BeginLoc.getLocWithOffset(Length);
79497949

79507950
DeclIDComp DIDComp(*this, *DInfo.Mod);
7951-
ArrayRef<serialization::LocalDeclID>::iterator
7952-
BeginIt = std::lower_bound(DInfo.Decls.begin(), DInfo.Decls.end(),
7953-
BeginLoc, DIDComp);
7951+
ArrayRef<serialization::LocalDeclID>::iterator BeginIt =
7952+
llvm::lower_bound(DInfo.Decls, BeginLoc, DIDComp);
79547953
if (BeginIt != DInfo.Decls.begin())
79557954
--BeginIt;
79567955

@@ -7962,9 +7961,8 @@ void ASTReader::FindFileRegionDecls(FileID File,
79627961
->isTopLevelDeclInObjCContainer())
79637962
--BeginIt;
79647963

7965-
ArrayRef<serialization::LocalDeclID>::iterator
7966-
EndIt = std::upper_bound(DInfo.Decls.begin(), DInfo.Decls.end(),
7967-
EndLoc, DIDComp);
7964+
ArrayRef<serialization::LocalDeclID>::iterator EndIt =
7965+
llvm::upper_bound(DInfo.Decls, EndLoc, DIDComp);
79687966
if (EndIt != DInfo.Decls.end())
79697967
++EndIt;
79707968

lib/Serialization/ASTWriter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5707,7 +5707,7 @@ void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) {
57075707
}
57085708

57095709
LocDeclIDsTy::iterator I =
5710-
std::upper_bound(Decls.begin(), Decls.end(), LocDecl, llvm::less_first());
5710+
llvm::upper_bound(Decls, LocDecl, llvm::less_first());
57115711

57125712
Decls.insert(I, LocDecl);
57135713
}

lib/StaticAnalyzer/Checkers/PaddingChecker.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,13 @@ class PaddingChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
274274
long long CurAlignmentBits = 1ull << (std::min)(TrailingZeros, 62u);
275275
CharUnits CurAlignment = CharUnits::fromQuantity(CurAlignmentBits);
276276
FieldInfo InsertPoint = {CurAlignment, CharUnits::Zero(), nullptr};
277-
auto CurBegin = Fields.begin();
278-
auto CurEnd = Fields.end();
279277

280278
// In the typical case, this will find the last element
281279
// of the vector. We won't find a middle element unless
282280
// we started on a poorly aligned address or have an overly
283281
// aligned field.
284-
auto Iter = std::upper_bound(CurBegin, CurEnd, InsertPoint);
285-
if (Iter != CurBegin) {
282+
auto Iter = llvm::upper_bound(Fields, InsertPoint);
283+
if (Iter != Fields.begin()) {
286284
// We found a field that we can layout with the current alignment.
287285
--Iter;
288286
NewOffset += Iter->Size;

lib/Tooling/InterpolatingCompilationDatabase.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,7 @@ class FileIndex {
478478
ArrayRef<SubstringAndIndex> Idx) const {
479479
assert(!Idx.empty());
480480
// Longest substring match will be adjacent to a direct lookup.
481-
auto It =
482-
std::lower_bound(Idx.begin(), Idx.end(), SubstringAndIndex{Key, 0});
481+
auto It = llvm::lower_bound(Idx, SubstringAndIndex{Key, 0});
483482
if (It == Idx.begin())
484483
return *It;
485484
if (It == Idx.end())

tools/diagtool/DiagnosticNames.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ const DiagnosticRecord &diagtool::getDiagnosticForID(short DiagID) {
5454
DiagnosticRecord Key = {nullptr, DiagID, 0};
5555

5656
const DiagnosticRecord *Result =
57-
std::lower_bound(std::begin(BuiltinDiagnosticsByID),
58-
std::end(BuiltinDiagnosticsByID),
59-
Key, orderByID);
57+
llvm::lower_bound(BuiltinDiagnosticsByID, Key, orderByID);
6058
assert(Result && "diagnostic not found; table may be out of date");
6159
return *Result;
6260
}

tools/diagtool/TreeView.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ class TreePrinter {
102102
return 1;
103103
}
104104

105-
const GroupRecord *Found =
106-
std::lower_bound(AllGroups.begin(), AllGroups.end(), RootGroup);
107-
105+
const GroupRecord *Found = llvm::lower_bound(AllGroups, RootGroup);
108106
if (Found == AllGroups.end() || Found->getName() != RootGroup) {
109107
llvm::errs() << "No such diagnostic group exists\n";
110108
return 1;

0 commit comments

Comments
 (0)