[clang-tools-extra] r301188 - [clang-tidy] Some Cleanups for performance-faster-string-find check.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 24 09:41:00 PDT 2017


Author: hokein
Date: Mon Apr 24 11:41:00 2017
New Revision: 301188

URL: http://llvm.org/viewvc/llvm-project?rev=301188&view=rev
Log:
[clang-tidy] Some Cleanups for performance-faster-string-find check.

NFC

Modified:
    clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp?rev=301188&r1=301187&r2=301188&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/performance/FasterStringFindCheck.cpp Mon Apr 24 11:41:00 2017
@@ -65,29 +65,19 @@ void FasterStringFindCheck::registerMatc
 
   const auto SingleChar =
       expr(ignoringParenCasts(stringLiteral(hasSize(1)).bind("literal")));
-
   const auto StringFindFunctions =
-      anyOf(hasName("find"), hasName("rfind"), hasName("find_first_of"),
-            hasName("find_first_not_of"), hasName("find_last_of"),
-            hasName("find_last_not_of"));
-
-  llvm::Optional<ast_matchers::internal::Matcher<NamedDecl>> IsStringClass;
-
-  for (const auto &ClassName : StringLikeClasses) {
-    const auto HasName = hasName(ClassName);
-    IsStringClass = IsStringClass ? anyOf(*IsStringClass, HasName) : HasName;
-  }
+      hasAnyName("find", "rfind", "find_first_of", "find_first_not_of",
+                 "find_last_of", "find_last_not_of");
 
-  if (IsStringClass) {
-    Finder->addMatcher(
-        cxxMemberCallExpr(
-            callee(functionDecl(StringFindFunctions).bind("func")),
-            anyOf(argumentCountIs(1), argumentCountIs(2)),
-            hasArgument(0, SingleChar),
-            on(expr(hasType(recordDecl(*IsStringClass)),
-                    unless(hasSubstitutedType())))),
-        this);
-  }
+  Finder->addMatcher(
+      cxxMemberCallExpr(
+          callee(functionDecl(StringFindFunctions).bind("func")),
+          anyOf(argumentCountIs(1), argumentCountIs(2)),
+          hasArgument(0, SingleChar),
+          on(expr(hasType(recordDecl(hasAnyName(SmallVector<StringRef, 4>(
+                      StringLikeClasses.begin(), StringLikeClasses.end())))),
+                  unless(hasSubstitutedType())))),
+      this);
 }
 
 void FasterStringFindCheck::check(const MatchFinder::MatchResult &Result) {




More information about the cfe-commits mailing list