[clang-tidy] Some Cleanups for performance-faster-string-find check.
authorHaojian Wu <hokein@google.com>
Mon, 24 Apr 2017 16:41:00 +0000 (16:41 +0000)
committerHaojian Wu <hokein@google.com>
Mon, 24 Apr 2017 16:41:00 +0000 (16:41 +0000)
NFC

llvm-svn: 301188

clang-tools-extra/clang-tidy/performance/FasterStringFindCheck.cpp

index a8a9f66..29dac1b 100644 (file)
@@ -65,29 +65,19 @@ void FasterStringFindCheck::registerMatchers(MatchFinder *Finder) {
 
   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;
-  }
-
-  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);
-  }
+      hasAnyName("find", "rfind", "find_first_of", "find_first_not_of",
+                 "find_last_of", "find_last_not_of");
+
+  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) {