Skip to content

Commit 3d4b7e8

Browse files
committed
[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
1 parent 909bf38 commit 3d4b7e8

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ UnusedUsingDeclsCheck::UnusedUsingDeclsCheck(StringRef Name,
5050
HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
5151

5252
void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) {
53+
// We don't emit warnings on unused-using-decls from headers, so bail out if
54+
// the main file is a header.
55+
if (utils::isFileExtension(getCurrentMainFile(), HeaderFileExtensions))
56+
return;
5357
Finder->addMatcher(usingDecl(isExpansionInMainFile()).bind("using"), this);
5458
auto DeclMatcher = hasDeclaration(namedDecl().bind("used"));
5559
Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)), this);
@@ -82,12 +86,6 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) {
8286
void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
8387
if (Result.Context->getDiagnostics().hasUncompilableErrorOccurred())
8488
return;
85-
// We don't emit warnings on unused-using-decls from headers, so bail out if
86-
// the main file is a header.
87-
if (auto MainFile = Result.SourceManager->getFileEntryRefForID(
88-
Result.SourceManager->getMainFileID());
89-
utils::isFileExtension(MainFile->getName(), HeaderFileExtensions))
90-
return;
9189

9290
if (const auto *Using = Result.Nodes.getNodeAs<UsingDecl>("using")) {
9391
// Ignores using-declarations defined in macros.

0 commit comments

Comments
 (0)