Skip to content

[clang-tools-extra] Use llvm::unique (NFC) #136514

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

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Apr 20, 2025

@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang-tidy

Author: Kazu Hirata (kazutakahirata)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/136514.diff

3 Files Affected:

  • (modified) clang-tools-extra/clang-doc/Representation.cpp (+2-2)
  • (modified) clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp (+9-9)
  • (modified) clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp (+1-2)
diff --git a/clang-tools-extra/clang-doc/Representation.cpp b/clang-tools-extra/clang-doc/Representation.cpp
index 54d2cb58ea2d9..9ab2f342d969a 100644
--- a/clang-tools-extra/clang-doc/Representation.cpp
+++ b/clang-tools-extra/clang-doc/Representation.cpp
@@ -200,7 +200,7 @@ void Info::mergeBase(Info &&Other) {
   std::move(Other.Description.begin(), Other.Description.end(),
             std::back_inserter(Description));
   llvm::sort(Description);
-  auto Last = std::unique(Description.begin(), Description.end());
+  auto Last = llvm::unique(Description);
   Description.erase(Last, Description.end());
 }
 
@@ -215,7 +215,7 @@ void SymbolInfo::merge(SymbolInfo &&Other) {
   // Unconditionally extend the list of locations, since we want all of them.
   std::move(Other.Loc.begin(), Other.Loc.end(), std::back_inserter(Loc));
   llvm::sort(Loc);
-  auto *Last = std::unique(Loc.begin(), Loc.end());
+  auto *Last = llvm::unique(Loc);
   Loc.erase(Last, Loc.end());
   mergeBase(std::move(Other));
 }
diff --git a/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp b/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp
index d7369b162dc10..4eac0617ed4a9 100644
--- a/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp
+++ b/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp
@@ -90,10 +90,10 @@ IncludeFixerContext::IncludeFixerContext(
                       std::make_pair(B.Range.getOffset(), B.Range.getLength());
              });
   QuerySymbolInfos.erase(
-      std::unique(QuerySymbolInfos.begin(), QuerySymbolInfos.end(),
-                  [](const QuerySymbolInfo &A, const QuerySymbolInfo &B) {
-                    return A.Range == B.Range;
-                  }),
+      llvm::unique(QuerySymbolInfos,
+                   [](const QuerySymbolInfo &A, const QuerySymbolInfo &B) {
+                     return A.Range == B.Range;
+                   }),
       QuerySymbolInfos.end());
   for (const auto &Symbol : MatchedSymbols) {
     HeaderInfos.push_back(
@@ -103,11 +103,11 @@ IncludeFixerContext::IncludeFixerContext(
              QuerySymbolInfos.front().ScopedQualifiers, Symbol)});
   }
   // Deduplicate header infos.
-  HeaderInfos.erase(std::unique(HeaderInfos.begin(), HeaderInfos.end(),
-                                [](const HeaderInfo &A, const HeaderInfo &B) {
-                                  return A.Header == B.Header &&
-                                         A.QualifiedName == B.QualifiedName;
-                                }),
+  HeaderInfos.erase(llvm::unique(HeaderInfos,
+                                 [](const HeaderInfo &A, const HeaderInfo &B) {
+                                   return A.Header == B.Header &&
+                                          A.QualifiedName == B.QualifiedName;
+                                 }),
                     HeaderInfos.end());
 }
 
diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 731141a545a48..b216970bfbd8c 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -754,8 +754,7 @@ std::vector<ClangTidyError> ClangTidyDiagnosticConsumer::take() {
   finalizeLastError();
 
   llvm::stable_sort(Errors, LessClangTidyError());
-  Errors.erase(std::unique(Errors.begin(), Errors.end(), EqualClangTidyError()),
-               Errors.end());
+  Errors.erase(llvm::unique(Errors, EqualClangTidyError()), Errors.end());
   if (RemoveIncompatibleErrors)
     removeIncompatibleErrors();
   return std::move(Errors);

@kazutakahirata kazutakahirata merged commit be48727 into llvm:main Apr 21, 2025
14 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_range_unique_clang_tools branch April 21, 2025 01:30
@carlosgalvezp
Copy link
Contributor

May I ask what is the reason for this change? What problem does std::unique have that llvm::unique solves?

@kazutakahirata
Copy link
Contributor Author

May I ask what is the reason for this change? What problem does std::unique have that llvm::unique solves?

  • llvm::unique(Foo) is shorter than std::unique(Foo.begin(), and Foo.end()).
  • llvm::unique(Foo) prevents us from mistakenly specifying two unrelated iterators like std::unique(This.begin(), That.end()).

https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/ADT/STLExtras.h has a collection of similar functions.

@carlosgalvezp
Copy link
Contributor

Thanks for the clarification!

IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants