Skip to content

[clangd] Use llvm::unique (NFC) #136470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/IncludeFixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ collectAccessibleScopes(Sema &Sem, const DeclarationNameInfo &Typo, Scope *S,
/*IncludeGlobalScope=*/false,
/*LoadExternal=*/false);
llvm::sort(Scopes);
Scopes.erase(std::unique(Scopes.begin(), Scopes.end()), Scopes.end());
Scopes.erase(llvm::unique(Scopes), Scopes.end());
return Scopes;
}

Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/InlayHints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ std::vector<InlayHint> inlayHints(ParsedAST &AST,
// De-duplicate hints. Duplicates can sometimes occur due to e.g. explicit
// template instantiations.
llvm::sort(Results);
Results.erase(std::unique(Results.begin(), Results.end()), Results.end());
Results.erase(llvm::unique(Results), Results.end());

return Results;
}
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/SemanticHighlighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ class HighlightingsBuilder {
// Initializer lists can give duplicates of tokens, therefore all tokens
// must be deduplicated.
llvm::sort(Tokens);
auto Last = std::unique(Tokens.begin(), Tokens.end());
auto Last = llvm::unique(Tokens);
Tokens.erase(Last, Tokens.end());

// Macros can give tokens that have the same source range but conflicting
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/SourceCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ std::vector<std::string> visibleNamespaces(llvm::StringRef Code,
return true;
return LHS < RHS;
});
Found.erase(std::unique(Found.begin(), Found.end()), Found.end());
Found.erase(llvm::unique(Found), Found.end());
return Found;
}

Expand Down
26 changes: 13 additions & 13 deletions clang-tools-extra/clangd/XRefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,13 +909,13 @@ class ReferenceFinder : public index::IndexDataConsumer {
return std::tie(LTok, L.Role) < std::tie(RTok, R.Role);
});
// We sometimes see duplicates when parts of the AST get traversed twice.
References.erase(std::unique(References.begin(), References.end(),
[](const Reference &L, const Reference &R) {
auto LTok = L.SpelledTok.location();
auto RTok = R.SpelledTok.location();
return std::tie(LTok, L.Role) ==
std::tie(RTok, R.Role);
}),
References.erase(llvm::unique(References,
[](const Reference &L, const Reference &R) {
auto LTok = L.SpelledTok.location();
auto RTok = R.SpelledTok.location();
return std::tie(LTok, L.Role) ==
std::tie(RTok, R.Role);
}),
References.end());
return std::move(References);
}
Expand Down Expand Up @@ -1502,12 +1502,12 @@ ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit,
// We may get multiple refs with the same location and different Roles, as
// cross-reference is only interested in locations, we deduplicate them
// by the location to avoid emitting duplicated locations.
MainFileRefs.erase(std::unique(MainFileRefs.begin(), MainFileRefs.end(),
[](const ReferenceFinder::Reference &L,
const ReferenceFinder::Reference &R) {
return L.SpelledTok.location() ==
R.SpelledTok.location();
}),
MainFileRefs.erase(llvm::unique(MainFileRefs,
[](const ReferenceFinder::Reference &L,
const ReferenceFinder::Reference &R) {
return L.SpelledTok.location() ==
R.SpelledTok.location();
}),
MainFileRefs.end());
for (const auto &Ref : MainFileRefs) {
ReferencesResult::Reference Result;
Expand Down
3 changes: 1 addition & 2 deletions clang-tools-extra/clangd/index/FileIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,7 @@ FileSymbols::buildIndex(IndexType Type, DuplicateHandling DuplicateHandle,
// relations being stored in both the shards containing their
// subject and object.
llvm::sort(AllRelations);
AllRelations.erase(std::unique(AllRelations.begin(), AllRelations.end()),
AllRelations.end());
AllRelations.erase(llvm::unique(AllRelations), AllRelations.end());

size_t StorageSize =
RefsStorage.size() * sizeof(Ref) + SymsStorage.size() * sizeof(Symbol);
Expand Down
3 changes: 1 addition & 2 deletions clang-tools-extra/clangd/index/Relation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ RelationSlab RelationSlab::Builder::build() && {
llvm::sort(Relations);

// Remove duplicates.
Relations.erase(std::unique(Relations.begin(), Relations.end()),
Relations.end());
Relations.erase(llvm::unique(Relations), Relations.end());

return RelationSlab{std::move(Relations)};
}
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/index/dex/Trigram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void generateIdentifierTrigrams(llvm::StringRef Identifier,
} else {
identifierTrigrams(Identifier, [&](Trigram T) { Result.push_back(T); });
llvm::sort(Result);
Result.erase(std::unique(Result.begin(), Result.end()), Result.end());
Result.erase(llvm::unique(Result), Result.end());
}
}

Expand Down
5 changes: 2 additions & 3 deletions clang-tools-extra/clangd/refactor/Rename.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ findOccurrencesOutsideFile(const NamedDecl &RenameDecl,
for (auto &FileAndOccurrences : AffectedFiles) {
auto &Ranges = FileAndOccurrences.getValue();
llvm::sort(Ranges);
Ranges.erase(std::unique(Ranges.begin(), Ranges.end()), Ranges.end());
Ranges.erase(llvm::unique(Ranges), Ranges.end());

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

assert(llvm::is_sorted(Occurrences));
assert(std::unique(Occurrences.begin(), Occurrences.end()) ==
Occurrences.end() &&
assert(llvm::unique(Occurrences) == Occurrences.end() &&
"Occurrences must be unique");

// These two always correspond to the same position.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ Expected<Tweak::Effect> RemoveUsingNamespace::apply(const Selection &Inputs) {
}
// Remove duplicates.
llvm::sort(IdentsToQualify);
IdentsToQualify.erase(
std::unique(IdentsToQualify.begin(), IdentsToQualify.end()),
IdentsToQualify.end());
IdentsToQualify.erase(llvm::unique(IdentsToQualify), IdentsToQualify.end());

// Produce replacements to remove the using directives.
tooling::Replacements R;
Expand Down
Loading