summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2017-05-16 15:44:42 +0000
committerAlexander Kornienko <alexfh@google.com>2017-05-16 15:44:42 +0000
commite133140fd1e5ea3a5bcadc3e594e1b613c36d9c5 (patch)
tree66868385e0d2b26bb82e47d84859f7779f56d51a /clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.cpp
parent464cecf81e054d4523fdb2198c7fbda297d9bf90 (diff)
downloadbcm5719-llvm-e133140fd1e5ea3a5bcadc3e594e1b613c36d9c5.tar.gz
bcm5719-llvm-e133140fd1e5ea3a5bcadc3e594e1b613c36d9c5.zip
[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. llvm-svn: 303180
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.cpp
index 20ce5d20658..fef76fdc9d7 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.cpp
@@ -267,10 +267,9 @@ void ImplicitBoolCastCheck::registerMatchers(MatchFinder *Finder) {
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::registerMatchers(MatchFinder *Finder) {
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::registerMatchers(MatchFinder *Finder) {
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::registerMatchers(MatchFinder *Finder) {
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);
}
OpenPOWER on IntegriCloud