Skip to content

Commit 277754c

Browse files
committed
[clangd] lower_bound -> bsearch, NFC
llvm-svn: 358561
1 parent 0080645 commit 277754c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

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

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

3737
SymbolSlab::const_iterator SymbolSlab::find(const SymbolID &ID) const {
38-
auto It = std::lower_bound(
39-
Symbols.begin(), Symbols.end(), ID,
40-
[](const Symbol &S, const SymbolID &I) { return S.ID < I; });
38+
auto It =
39+
llvm::bsearch(Symbols, [&](const Symbol &S) { return !(S.ID < ID); });
4140
if (It != Symbols.end() && It->ID == ID)
4241
return It;
4342
return Symbols.end();

clang-tools-extra/clangd/index/dex/PostingList.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "PostingList.h"
1010
#include "Iterator.h"
1111
#include "Token.h"
12+
#include "llvm/ADT/STLExtras.h"
1213
#include "llvm/Support/Error.h"
1314
#include "llvm/Support/MathExtras.h"
1415

@@ -49,7 +50,8 @@ class ChunkIterator : public Iterator {
4950
return;
5051
advanceToChunk(ID);
5152
// Try to find ID within current chunk.
52-
CurrentID = std::lower_bound(CurrentID, std::end(DecompressedChunk), ID);
53+
CurrentID = llvm::bsearch(CurrentID, DecompressedChunk.end(),
54+
[&](const DocID D) { return D >= ID; });
5355
normalizeCursor();
5456
}
5557

@@ -100,10 +102,9 @@ class ChunkIterator : public Iterator {
100102
void advanceToChunk(DocID ID) {
101103
if ((CurrentChunk != Chunks.end() - 1) &&
102104
((CurrentChunk + 1)->Head <= ID)) {
103-
// Find the next chunk with Head >= ID.
104-
CurrentChunk = std::lower_bound(
105-
CurrentChunk + 1, Chunks.end(), ID,
106-
[](const Chunk &C, const DocID ID) { return C.Head <= ID; });
105+
CurrentChunk =
106+
llvm::bsearch(CurrentChunk + 1, Chunks.end(),
107+
[&](const Chunk &C) { return C.Head >= ID; });
107108
--CurrentChunk;
108109
DecompressedChunk = CurrentChunk->decompress();
109110
CurrentID = DecompressedChunk.begin();

0 commit comments

Comments
 (0)