diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2015-08-31 15:28:57 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2015-08-31 15:28:57 +0000 |
commit | bf89109013bc51868173de3d8c71d28989afd39e (patch) | |
tree | 434ce8b894754eef5a23ba04b53e09a7da674459 /clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp | |
parent | 54f3657448fd127fd00162058c9f1f56f966fc18 (diff) | |
download | bcm5719-llvm-bf89109013bc51868173de3d8c71d28989afd39e.tar.gz bcm5719-llvm-bf89109013bc51868173de3d8c71d28989afd39e.zip |
Using an early return as it is more clear; NFC.
llvm-svn: 246447
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp b/clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp index 17ef560227f..a9a1a092031 100644 --- a/clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/InefficientAlgorithmCheck.cpp @@ -30,33 +30,34 @@ static bool areTypesCompatible(QualType Left, QualType Right) { void InefficientAlgorithmCheck::registerMatchers(MatchFinder *Finder) { // Only register the matchers for C++; the functionality currently does not // provide any benefit to other languages, despite being benign. - if (getLangOpts().CPlusPlus) { - const std::string Algorithms = - "^::std::(find|count|equal_range|lower_bound|upper_bound)$"; - const auto ContainerMatcher = classTemplateSpecializationDecl( - matchesName("^::std::(unordered_)?(multi)?(set|map)$")); - const auto Matcher = - callExpr( - callee(functionDecl(matchesName(Algorithms))), - hasArgument( - 0, constructExpr(has(memberCallExpr( - callee(methodDecl(hasName("begin"))), - on(declRefExpr( - hasDeclaration(decl().bind("IneffContObj")), - anyOf(hasType(ContainerMatcher.bind("IneffCont")), - hasType(pointsTo(ContainerMatcher.bind( - "IneffContPtr"))))) - .bind("IneffContExpr")))))), - hasArgument(1, constructExpr(has(memberCallExpr( - callee(methodDecl(hasName("end"))), - on(declRefExpr(hasDeclaration( - equalsBoundNode("IneffContObj")))))))), - hasArgument(2, expr().bind("AlgParam")), - unless(isInTemplateInstantiation())) - .bind("IneffAlg"); - - Finder->addMatcher(Matcher, this); - } + if (!getLangOpts().CPlusPlus) + return; + + const std::string Algorithms = + "^::std::(find|count|equal_range|lower_bound|upper_bound)$"; + const auto ContainerMatcher = classTemplateSpecializationDecl( + matchesName("^::std::(unordered_)?(multi)?(set|map)$")); + const auto Matcher = + callExpr( + callee(functionDecl(matchesName(Algorithms))), + hasArgument( + 0, constructExpr(has(memberCallExpr( + callee(methodDecl(hasName("begin"))), + on(declRefExpr( + hasDeclaration(decl().bind("IneffContObj")), + anyOf(hasType(ContainerMatcher.bind("IneffCont")), + hasType(pointsTo( + ContainerMatcher.bind("IneffContPtr"))))) + .bind("IneffContExpr")))))), + hasArgument(1, constructExpr(has(memberCallExpr( + callee(methodDecl(hasName("end"))), + on(declRefExpr(hasDeclaration( + equalsBoundNode("IneffContObj")))))))), + hasArgument(2, expr().bind("AlgParam")), + unless(isInTemplateInstantiation())) + .bind("IneffAlg"); + + Finder->addMatcher(Matcher, this); } void InefficientAlgorithmCheck::check(const MatchFinder::MatchResult &Result) { |