Skip to content

Commit 8e6d6a5

Browse files
authored
[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
1 parent 46a08ce commit 8e6d6a5

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
@@ -51,6 +51,10 @@ UnusedUsingDeclsCheck::UnusedUsingDeclsCheck(StringRef Name,
5151
HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
5252

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

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

0 commit comments

Comments
 (0)