[clang-tools-extra] [clang-tidy][NFC] optimize unused using decls performance (PR #110200)
Congcong Cai via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 28 06:18:15 PDT 2024
https://github.com/HerrCai0907 updated https://github.com/llvm/llvm-project/pull/110200
>From aee3cc16d9c36d2cc56247ec14f72730c7b65e80 Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0907 at 163.com>
Date: Thu, 26 Sep 2024 17:48:48 +0800
Subject: [PATCH 1/2] [clang-tidy][NFC] optimize unused using decls performance
---
.../clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 90b317527ee410..3c8dd6e9d239d9 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -25,6 +25,13 @@ AST_MATCHER_P(DeducedTemplateSpecializationType, refsToTemplatedDecl,
return false;
}
+AST_MATCHER_P(Type, getTagDecl, clang::ast_matchers::internal::Matcher<TagDecl>,
+ DeclMatcher) {
+ if (const auto *ND = Node.getAsTagDecl())
+ return DeclMatcher.matches(*ND, Finder, Builder);
+ return false;
+}
+
} // namespace
// A function that helps to tell whether a TargetDecl in a UsingDecl will be
@@ -61,7 +68,8 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(userDefinedLiteral().bind("used"), this);
Finder->addMatcher(
loc(elaboratedType(unless(hasQualifier(nestedNameSpecifier())),
- hasUnqualifiedDesugaredType(type().bind("usedType")))),
+ hasUnqualifiedDesugaredType(
+ type(getTagDecl(tagDecl().bind("used")))))),
this);
// Cases where we can identify the UsingShadowDecl directly, rather than
// just its target.
@@ -139,12 +147,6 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
return;
}
- if (const auto *T = Result.Nodes.getNodeAs<Type>("usedType")) {
- if (const auto *ND = T->getAsTagDecl())
- RemoveNamedDecl(ND);
- return;
- }
-
if (const auto *UsedShadow =
Result.Nodes.getNodeAs<UsingShadowDecl>("usedShadow")) {
removeFromFoundDecls(UsedShadow->getTargetDecl());
>From c195ec2aa81496d6e963e4db591ea19deec95462 Mon Sep 17 00:00:00 2001
From: Congcong Cai <congcongcai0907 at 163.com>
Date: Sat, 28 Sep 2024 21:18:08 +0800
Subject: [PATCH 2/2] Update
clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
---
clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 3c8dd6e9d239d9..700b0548c714cf 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -27,7 +27,7 @@ AST_MATCHER_P(DeducedTemplateSpecializationType, refsToTemplatedDecl,
AST_MATCHER_P(Type, getTagDecl, clang::ast_matchers::internal::Matcher<TagDecl>,
DeclMatcher) {
- if (const auto *ND = Node.getAsTagDecl())
+ if (const TagDecl *ND = Node.getAsTagDecl())
return DeclMatcher.matches(*ND, Finder, Builder);
return false;
}
More information about the cfe-commits
mailing list