[clang-tools-extra] 8e6d6a5 - [clang-tidy][NFC] improve performance misc-unused-using-decls (#123454)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 24 03:32:15 PST 2025


Author: Congcong Cai
Date: 2025-01-24T19:32:11+08:00
New Revision: 8e6d6a55108c7979f0392bf8ad3444c92a2474e9

URL: https://github.com/llvm/llvm-project/commit/8e6d6a55108c7979f0392bf8ad3444c92a2474e9
DIFF: https://github.com/llvm/llvm-project/commit/8e6d6a55108c7979f0392bf8ad3444c92a2474e9.diff

LOG: [clang-tidy][NFC] improve performance misc-unused-using-decls (#123454)

skip header file before register AST Matchers
it can avoid to matcher lots of ast node when lint header file

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 4448e9ccba80d9..5d74907aa9fabb 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -51,6 +51,10 @@ UnusedUsingDeclsCheck::UnusedUsingDeclsCheck(StringRef Name,
       HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
 
 void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) {
+  // We don't emit warnings on unused-using-decls from headers, so bail out if
+  // the main file is a header.
+  if (utils::isFileExtension(getCurrentMainFile(), HeaderFileExtensions))
+    return;
   Finder->addMatcher(usingDecl(isExpansionInMainFile()).bind("using"), this);
   auto DeclMatcher = hasDeclaration(namedDecl().bind("used"));
   Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)), this);
@@ -83,12 +87,6 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) {
 void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
   if (Result.Context->getDiagnostics().hasUncompilableErrorOccurred())
     return;
-  // We don't emit warnings on unused-using-decls from headers, so bail out if
-  // the main file is a header.
-  if (auto MainFile = Result.SourceManager->getFileEntryRefForID(
-          Result.SourceManager->getMainFileID());
-      utils::isFileExtension(MainFile->getName(), HeaderFileExtensions))
-    return;
 
   if (const auto *Using = Result.Nodes.getNodeAs<UsingDecl>("using")) {
     // Ignores using-declarations defined in macros.


        


More information about the cfe-commits mailing list