[clang-tools-extra] r303180 - [clang-tidy] Optimize matchers in readability-implicit-bool-cast. NFC
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Tue May 16 08:44:42 PDT 2017
Author: alexfh
Date: Tue May 16 10:44:42 2017
New Revision: 303180
URL: http://llvm.org/viewvc/llvm-project?rev=303180&view=rev
Log:
[clang-tidy] Optimize matchers in readability-implicit-bool-cast. NFC
Don't repeat `isInTemplateInstantiation()` and `hasAncestor()` unnecessarily.
This speeds up the check by a factor of up to 3 on some large files.
Modified:
clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp
Modified: clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp?rev=303180&r1=303179&r2=303180&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp Tue May 16 10:44:42 2017
@@ -267,10 +267,9 @@ void ImplicitBoolCastCheck::registerMatc
return;
}
- auto exceptionCases = expr(
- anyOf(hasParent(explicitCastExpr()),
- allOf(isMacroExpansion(), unless(isNULLMacroExpansion())),
- isInTemplateInstantiation(), hasAncestor(functionTemplateDecl())));
+ auto exceptionCases =
+ expr(anyOf(hasParent(explicitCastExpr()),
+ allOf(isMacroExpansion(), unless(isNULLMacroExpansion()))));
auto implicitCastFromBool = implicitCastExpr(
unless(exceptionCases),
anyOf(hasCastKind(CK_IntegralCast), hasCastKind(CK_IntegralToFloating),
@@ -285,8 +284,7 @@ void ImplicitBoolCastCheck::registerMatc
Finder->addMatcher(
implicitCastExpr(
// Exclude cases common to implicit cast to and from bool.
- unless(exceptionCases),
- unless(has(boolXor)),
+ unless(exceptionCases), unless(has(boolXor)),
// Exclude case of using if or while statements with variable
// declaration, e.g.:
// if (int var = functionCall()) {}
@@ -298,7 +296,9 @@ void ImplicitBoolCastCheck::registerMatc
hasCastKind(CK_MemberPointerToBoolean)),
// Retrive also parent statement, to check if we need additional
// parens in replacement.
- anyOf(hasParent(stmt().bind("parentStmt")), anything()))
+ anyOf(hasParent(stmt().bind("parentStmt")), anything()),
+ unless(isInTemplateInstantiation()),
+ unless(hasAncestor(functionTemplateDecl())))
.bind("implicitCastToBool"),
this);
@@ -319,7 +319,9 @@ void ImplicitBoolCastCheck::registerMatc
anyOf(boolComparison, boolXor, boolOpAssignment)))),
// Check also for nested casts, for example: bool -> int -> float.
anyOf(hasParent(implicitCastExpr().bind("furtherImplicitCast")),
- anything()))
+ anything()),
+ unless(isInTemplateInstantiation()),
+ unless(hasAncestor(functionTemplateDecl())))
.bind("implicitCastFromBool"),
this);
}
More information about the cfe-commits
mailing list