diff options
| author | Alexander Kornienko <alexfh@google.com> | 2017-05-16 16:40:46 +0000 |
|---|---|---|
| committer | Alexander Kornienko <alexfh@google.com> | 2017-05-16 16:40:46 +0000 |
| commit | 50de3ad34185419fda1defb26aeefa783dad6c10 (patch) | |
| tree | 053b4f07fd101afa53f1a26221d3382efe94d85b /clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.cpp | |
| parent | acca0f5c02584702b0ee14ce747a565d9f157bd4 (diff) | |
| download | bcm5719-llvm-50de3ad34185419fda1defb26aeefa783dad6c10.tar.gz bcm5719-llvm-50de3ad34185419fda1defb26aeefa783dad6c10.zip | |
[clang-tidy] Optimize readability-implicit-bool-cast, NFC
Rearrange matchers to put the most expensive ones closer to the end. Speed up
another 3-5x on some files.
llvm-svn: 303187
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.cpp')
| -rw-r--r-- | clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.cpp index fef76fdc9d7..996219c8bd8 100644 --- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolCastCheck.cpp @@ -268,32 +268,32 @@ void ImplicitBoolCastCheck::registerMatchers(MatchFinder *Finder) { } auto exceptionCases = - expr(anyOf(hasParent(explicitCastExpr()), - allOf(isMacroExpansion(), unless(isNULLMacroExpansion())))); + expr(anyOf(allOf(isMacroExpansion(), unless(isNULLMacroExpansion())), + hasParent(explicitCastExpr()))); auto implicitCastFromBool = implicitCastExpr( - unless(exceptionCases), anyOf(hasCastKind(CK_IntegralCast), hasCastKind(CK_IntegralToFloating), // Prior to C++11 cast from bool literal to pointer was allowed. allOf(anyOf(hasCastKind(CK_NullToPointer), hasCastKind(CK_NullToMemberPointer)), hasSourceExpression(cxxBoolLiteral()))), - hasSourceExpression(expr(hasType(booleanType())))); + hasSourceExpression(expr(hasType(booleanType()))), + unless(exceptionCases)); auto boolXor = binaryOperator(hasOperatorName("^"), hasLHS(implicitCastFromBool), hasRHS(implicitCastFromBool)); Finder->addMatcher( implicitCastExpr( - // Exclude cases common to implicit cast to and from bool. - unless(exceptionCases), unless(has(boolXor)), + anyOf(hasCastKind(CK_IntegralToBoolean), + hasCastKind(CK_FloatingToBoolean), + hasCastKind(CK_PointerToBoolean), + hasCastKind(CK_MemberPointerToBoolean)), // Exclude case of using if or while statements with variable // declaration, e.g.: // if (int var = functionCall()) {} unless( hasParent(stmt(anyOf(ifStmt(), whileStmt()), has(declStmt())))), - anyOf(hasCastKind(CK_IntegralToBoolean), - hasCastKind(CK_FloatingToBoolean), - hasCastKind(CK_PointerToBoolean), - hasCastKind(CK_MemberPointerToBoolean)), + // Exclude cases common to implicit cast to and from bool. + unless(exceptionCases), unless(has(boolXor)), // Retrive also parent statement, to check if we need additional // parens in replacement. anyOf(hasParent(stmt().bind("parentStmt")), anything()), |

