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. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits