-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang-tidy][NFC] optimize unused using decls performance #110200
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
Conversation
@llvm/pr-subscribers-clang-tools-extra Author: Congcong Cai (HerrCai0907) ChangesFull diff: https://github.com/llvm/llvm-project/pull/110200.diff 1 Files Affected:
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());
|
@llvm/pr-subscribers-clang-tidy Author: Congcong Cai (HerrCai0907) ChangesFull diff: https://github.com/llvm/llvm-project/pull/110200.diff 1 Files Affected:
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());
|
@@ -25,6 +25,13 @@ AST_MATCHER_P(DeducedTemplateSpecializationType, refsToTemplatedDecl, | |||
return false; | |||
} | |||
|
|||
AST_MATCHER_P(Type, getTagDecl, clang::ast_matchers::internal::Matcher<TagDecl>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
asTagDecl
maybe?
This might help with #72300. |
Yes. but not much. It can optimize about 5% execution time for some files in llvm projects. |
Improve performance by moving the check forward to the matching stage