|
17 | 17 | using namespace clang;
|
18 | 18 | using namespace clang::index;
|
19 | 19 |
|
20 |
| -static void addOccurrence(std::vector<DeclOccurrence> &Decls, |
21 |
| - DeclOccurrence Info) { |
22 |
| - auto IsNextOccurence = [&]() -> bool { |
23 |
| - if (Decls.empty()) |
24 |
| - return true; |
25 |
| - auto &Last = Decls.back(); |
26 |
| - return Last.Offset < Info.Offset; |
27 |
| - }; |
28 |
| - |
29 |
| - if (IsNextOccurence()) { |
30 |
| - Decls.push_back(std::move(Info)); |
31 |
| - return; |
| 20 | +ArrayRef<DeclOccurrence> |
| 21 | +FileIndexRecord::getDeclOccurrencesSortedByOffset() const { |
| 22 | + if (!IsSorted) { |
| 23 | + llvm::stable_sort(Decls, |
| 24 | + [](const DeclOccurrence &A, const DeclOccurrence &B) { |
| 25 | + return A.Offset < B.Offset; |
| 26 | + }); |
| 27 | + IsSorted = true; |
32 | 28 | }
|
33 |
| - |
34 |
| - // We keep Decls in order as we need to access them in this order in all cases. |
35 |
| - auto It = llvm::upper_bound(Decls, Info); |
36 |
| - Decls.insert(It, std::move(Info)); |
| 29 | + return Decls; |
37 | 30 | }
|
38 | 31 |
|
39 | 32 | void FileIndexRecord::addDeclOccurence(SymbolRoleSet Roles, unsigned Offset,
|
40 | 33 | const Decl *D,
|
41 | 34 | ArrayRef<SymbolRelation> Relations) {
|
42 | 35 | assert(D->isCanonicalDecl() &&
|
43 | 36 | "Occurrences should be associated with their canonical decl");
|
44 |
| - addOccurrence(Decls, DeclOccurrence(Roles, Offset, D, Relations)); |
| 37 | + IsSorted = false; |
| 38 | + Decls.emplace_back(Roles, Offset, D, Relations); |
45 | 39 | }
|
46 | 40 |
|
47 | 41 | void FileIndexRecord::addMacroOccurence(SymbolRoleSet Roles, unsigned Offset,
|
48 | 42 | const IdentifierInfo *Name,
|
49 | 43 | const MacroInfo *MI) {
|
50 |
| - addOccurrence(Decls, DeclOccurrence(Roles, Offset, Name, MI)); |
| 44 | + IsSorted = false; |
| 45 | + Decls.emplace_back(Roles, Offset, Name, MI); |
51 | 46 | }
|
52 | 47 |
|
53 | 48 | void FileIndexRecord::removeHeaderGuardMacros() {
|
|
0 commit comments