[clang-tools-extra] r303187 - [clang-tidy] Optimize readability-implicit-bool-cast, NFC
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Tue May 16 09:40:46 PDT 2017
Author: alexfh
Date: Tue May 16 11:40:46 2017
New Revision: 303187
URL: http://llvm.org/viewvc/llvm-project?rev=303187&view=rev
Log:
[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.
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=303187&r1=303186&r2=303187&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolCastCheck.cpp Tue May 16 11:40:46 2017
@@ -268,32 +268,32 @@ void ImplicitBoolCastCheck::registerMatc
}
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()),
More information about the cfe-commits
mailing list