[clang-tools-extra] [clang-tidy][NFC] improve performance misc-unused-using-decls (PR #123454)
Congcong Cai via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 17 23:47:25 PST 2025
https://github.com/HerrCai0907 created https://github.com/llvm/llvm-project/pull/123454
skip header file before register AST Matchers
it can avoid to matcher lots of ast node when lint header file
>From 3d4b7e8776af4a51618febb45ba55e3f3428ca64 Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0907 at 163.com>
Date: Sat, 18 Jan 2025 15:42:07 +0800
Subject: [PATCH] [clang-tidy][NFC] improve performance misc-unused-using-decls
skip header file before register AST Matchers
it can avoid to matcher lots of ast node when lint header file
---
.../clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 1ff61bae46b1ed..ebf9e7c19ca842 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -50,6 +50,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);
@@ -82,12 +86,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