Skip to content

Commit 9bcb18d

Browse files
[clangd] Use llvm::unique (NFC) (#136470)
1 parent f2ec5e4 commit 9bcb18d

File tree

10 files changed

+23
-28
lines changed

10 files changed

+23
-28
lines changed

clang-tools-extra/clangd/IncludeFixer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ collectAccessibleScopes(Sema &Sem, const DeclarationNameInfo &Typo, Scope *S,
484484
/*IncludeGlobalScope=*/false,
485485
/*LoadExternal=*/false);
486486
llvm::sort(Scopes);
487-
Scopes.erase(std::unique(Scopes.begin(), Scopes.end()), Scopes.end());
487+
Scopes.erase(llvm::unique(Scopes), Scopes.end());
488488
return Scopes;
489489
}
490490

clang-tools-extra/clangd/InlayHints.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ std::vector<InlayHint> inlayHints(ParsedAST &AST,
11941194
// De-duplicate hints. Duplicates can sometimes occur due to e.g. explicit
11951195
// template instantiations.
11961196
llvm::sort(Results);
1197-
Results.erase(std::unique(Results.begin(), Results.end()), Results.end());
1197+
Results.erase(llvm::unique(Results), Results.end());
11981198

11991199
return Results;
12001200
}

clang-tools-extra/clangd/SemanticHighlighting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ class HighlightingsBuilder {
489489
// Initializer lists can give duplicates of tokens, therefore all tokens
490490
// must be deduplicated.
491491
llvm::sort(Tokens);
492-
auto Last = std::unique(Tokens.begin(), Tokens.end());
492+
auto Last = llvm::unique(Tokens);
493493
Tokens.erase(Last, Tokens.end());
494494

495495
// Macros can give tokens that have the same source range but conflicting

clang-tools-extra/clangd/SourceCode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ std::vector<std::string> visibleNamespaces(llvm::StringRef Code,
864864
return true;
865865
return LHS < RHS;
866866
});
867-
Found.erase(std::unique(Found.begin(), Found.end()), Found.end());
867+
Found.erase(llvm::unique(Found), Found.end());
868868
return Found;
869869
}
870870

clang-tools-extra/clangd/XRefs.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -909,13 +909,13 @@ class ReferenceFinder : public index::IndexDataConsumer {
909909
return std::tie(LTok, L.Role) < std::tie(RTok, R.Role);
910910
});
911911
// We sometimes see duplicates when parts of the AST get traversed twice.
912-
References.erase(std::unique(References.begin(), References.end(),
913-
[](const Reference &L, const Reference &R) {
914-
auto LTok = L.SpelledTok.location();
915-
auto RTok = R.SpelledTok.location();
916-
return std::tie(LTok, L.Role) ==
917-
std::tie(RTok, R.Role);
918-
}),
912+
References.erase(llvm::unique(References,
913+
[](const Reference &L, const Reference &R) {
914+
auto LTok = L.SpelledTok.location();
915+
auto RTok = R.SpelledTok.location();
916+
return std::tie(LTok, L.Role) ==
917+
std::tie(RTok, R.Role);
918+
}),
919919
References.end());
920920
return std::move(References);
921921
}
@@ -1502,12 +1502,12 @@ ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit,
15021502
// We may get multiple refs with the same location and different Roles, as
15031503
// cross-reference is only interested in locations, we deduplicate them
15041504
// by the location to avoid emitting duplicated locations.
1505-
MainFileRefs.erase(std::unique(MainFileRefs.begin(), MainFileRefs.end(),
1506-
[](const ReferenceFinder::Reference &L,
1507-
const ReferenceFinder::Reference &R) {
1508-
return L.SpelledTok.location() ==
1509-
R.SpelledTok.location();
1510-
}),
1505+
MainFileRefs.erase(llvm::unique(MainFileRefs,
1506+
[](const ReferenceFinder::Reference &L,
1507+
const ReferenceFinder::Reference &R) {
1508+
return L.SpelledTok.location() ==
1509+
R.SpelledTok.location();
1510+
}),
15111511
MainFileRefs.end());
15121512
for (const auto &Ref : MainFileRefs) {
15131513
ReferencesResult::Reference Result;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,7 @@ FileSymbols::buildIndex(IndexType Type, DuplicateHandling DuplicateHandle,
370370
// relations being stored in both the shards containing their
371371
// subject and object.
372372
llvm::sort(AllRelations);
373-
AllRelations.erase(std::unique(AllRelations.begin(), AllRelations.end()),
374-
AllRelations.end());
373+
AllRelations.erase(llvm::unique(AllRelations), AllRelations.end());
375374

376375
size_t StorageSize =
377376
RefsStorage.size() * sizeof(Ref) + SymsStorage.size() * sizeof(Symbol);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ RelationSlab RelationSlab::Builder::build() && {
4343
llvm::sort(Relations);
4444

4545
// Remove duplicates.
46-
Relations.erase(std::unique(Relations.begin(), Relations.end()),
47-
Relations.end());
46+
Relations.erase(llvm::unique(Relations), Relations.end());
4847

4948
return RelationSlab{std::move(Relations)};
5049
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void generateIdentifierTrigrams(llvm::StringRef Identifier,
116116
} else {
117117
identifierTrigrams(Identifier, [&](Trigram T) { Result.push_back(T); });
118118
llvm::sort(Result);
119-
Result.erase(std::unique(Result.begin(), Result.end()), Result.end());
119+
Result.erase(llvm::unique(Result), Result.end());
120120
}
121121
}
122122

clang-tools-extra/clangd/refactor/Rename.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ findOccurrencesOutsideFile(const NamedDecl &RenameDecl,
906906
for (auto &FileAndOccurrences : AffectedFiles) {
907907
auto &Ranges = FileAndOccurrences.getValue();
908908
llvm::sort(Ranges);
909-
Ranges.erase(std::unique(Ranges.begin(), Ranges.end()), Ranges.end());
909+
Ranges.erase(llvm::unique(Ranges), Ranges.end());
910910

911911
SPAN_ATTACH(Tracer, FileAndOccurrences.first(),
912912
static_cast<int64_t>(Ranges.size()));
@@ -1210,8 +1210,7 @@ llvm::Expected<Edit> buildRenameEdit(llvm::StringRef AbsFilePath,
12101210
static_cast<int64_t>(Occurrences.size()));
12111211

12121212
assert(llvm::is_sorted(Occurrences));
1213-
assert(std::unique(Occurrences.begin(), Occurrences.end()) ==
1214-
Occurrences.end() &&
1213+
assert(llvm::unique(Occurrences) == Occurrences.end() &&
12151214
"Occurrences must be unique");
12161215

12171216
// These two always correspond to the same position.

clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,7 @@ Expected<Tweak::Effect> RemoveUsingNamespace::apply(const Selection &Inputs) {
196196
}
197197
// Remove duplicates.
198198
llvm::sort(IdentsToQualify);
199-
IdentsToQualify.erase(
200-
std::unique(IdentsToQualify.begin(), IdentsToQualify.end()),
201-
IdentsToQualify.end());
199+
IdentsToQualify.erase(llvm::unique(IdentsToQualify), IdentsToQualify.end());
202200

203201
// Produce replacements to remove the using directives.
204202
tooling::Replacements R;

0 commit comments

Comments
 (0)