[clang-tools-extra] [clang-tidy][NFC] Run `performance-faster-string-find` over the codebase (PR #189202)

via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 28 17:44:32 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-tools-extra

Author: Victor Chernyakin (localspook)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/189202.diff


11 Files Affected:

- (modified) clang-tools-extra/clang-tidy/ClangTidy.cpp (+1-1) 
- (modified) clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp (+1-1) 
- (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.cpp (+1-1) 
- (modified) clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp (+1-1) 
- (modified) clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp (+3-3) 
- (modified) clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp (+1-1) 
- (modified) clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp (+7-7) 
- (modified) clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp (+4-4) 
- (modified) clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.cpp (+1-1) 
- (modified) clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp (+1-1) 
- (modified) clang-tools-extra/clang-tidy/utils/Matchers.h (+2-2) 


``````````diff
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 60f4823d930c1..787e37078c396 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -571,7 +571,7 @@ runClangTidy(ClangTidyContext &Context, const CompilationDatabase &Compilations,
         CommandLineArguments AdjustedArgs = Args;
         if (Opts.ExtraArgsBefore) {
           auto I = AdjustedArgs.begin();
-          if (I != AdjustedArgs.end() && !StringRef(*I).starts_with("-"))
+          if (I != AdjustedArgs.end() && !StringRef(*I).starts_with('-'))
             ++I; // Skip compiler binary name, if it is there.
           AdjustedArgs.insert(I, Opts.ExtraArgsBefore->begin(),
                               Opts.ExtraArgsBefore->end());
diff --git a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
index f8db3602f0ec7..66c80dae0c8ef 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
@@ -102,7 +102,7 @@ static std::optional<std::string> getUnderscoreCapitalFixup(StringRef Name) {
 static bool startsWithUnderscoreInGlobalNamespace(StringRef Name,
                                                   bool IsInGlobalNamespace,
                                                   bool IsMacro) {
-  return !IsMacro && IsInGlobalNamespace && Name.starts_with("_");
+  return !IsMacro && IsInGlobalNamespace && Name.starts_with('_');
 }
 
 static std::optional<std::string>
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.cpp
index a98dabbb14f5f..83afaa07b37ed 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.cpp
@@ -214,7 +214,7 @@ void ProBoundsAvoidUncheckedContainerAccessCheck::check(
           "(";
 
       if (Callee->isArrow())
-        BeginInsertion += "*";
+        BeginInsertion += '*';
 
       // Since C++23, the subscript operator may also be called without an
       // argument, which makes the following distinction necessary
diff --git a/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp b/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp
index e041e83ccb2fd..0c2f289d16922 100644
--- a/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp
@@ -27,7 +27,7 @@ int main(int argc, char *argv[]) {
   std::vector<std::pair<llvm::UTF32, SmallVector<llvm::UTF32>>> Entries;
   SmallVector<StringRef> Values;
   for (const StringRef Line : Lines) {
-    if (Line.starts_with("#"))
+    if (Line.starts_with('#'))
       continue;
 
     Values.clear();
diff --git a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
index 94232fa2ff626..0097ea54ba548 100644
--- a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
@@ -65,8 +65,8 @@ IncludeCleanerCheck::IncludeCleanerCheck(StringRef Name,
     if (!llvm::Regex{Header}.isValid())
       configurationDiag("Invalid ignore headers regex '%0'") << Header;
     std::string HeaderSuffix{Header.str()};
-    if (!Header.ends_with("$"))
-      HeaderSuffix += "$";
+    if (!Header.ends_with('$'))
+      HeaderSuffix += '$';
     IgnoreHeadersRegex.emplace_back(HeaderSuffix);
   }
 
@@ -227,7 +227,7 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) {
     for (const auto &Inc : Missing) {
       const std::string Spelling = include_cleaner::spellHeader(
           {Inc.Missing, PP->getHeaderSearchInfo(), MainFile});
-      const bool Angled = StringRef{Spelling}.starts_with("<");
+      const bool Angled = StringRef{Spelling}.starts_with('<');
       // We might suggest insertion of an existing include in edge cases, e.g.,
       // include is present in a PP-disabled region, or spelling of the header
       // turns out to be the same as one of the unresolved includes in the
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index 0179f649a0e9f..1ba209fed5a27 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -650,7 +650,7 @@ void LoopConvertCheck::doConversion(
 
       VarNameOrStructuredBinding.erase(VarNameOrStructuredBinding.size() - 2,
                                        2);
-      VarNameOrStructuredBinding += "]";
+      VarNameOrStructuredBinding += ']';
     } else {
       VarNameOrStructuredBinding = AliasVar->getName().str();
 
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 17fbfcf1fb181..3bf7d7eb18529 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -894,7 +894,7 @@ bool IdentifierNamingCheck::matchesStyle(
 
   // Ensure the name doesn't have any extra underscores beyond those specified
   // in the prefix and suffix.
-  if (Name.starts_with("_") || Name.ends_with("_"))
+  if (Name.starts_with('_') || Name.ends_with('_'))
     return false;
 
   if (Style.Case && !Matchers[static_cast<size_t>(*Style.Case)].match(Name))
@@ -950,7 +950,7 @@ std::string IdentifierNamingCheck::fixupWithCase(
   case IdentifierNamingCheck::CT_LowerCase:
     for (const auto &Word : Words) {
       if (&Word != &Words.front())
-        Fixup += "_";
+        Fixup += '_';
       Fixup += Word.lower();
     }
     break;
@@ -958,7 +958,7 @@ std::string IdentifierNamingCheck::fixupWithCase(
   case IdentifierNamingCheck::CT_UpperCase:
     for (const auto &Word : Words) {
       if (&Word != &Words.front())
-        Fixup += "_";
+        Fixup += '_';
       Fixup += Word.upper();
     }
     break;
@@ -984,7 +984,7 @@ std::string IdentifierNamingCheck::fixupWithCase(
   case IdentifierNamingCheck::CT_CamelSnakeCase:
     for (const auto &Word : Words) {
       if (&Word != &Words.front())
-        Fixup += "_";
+        Fixup += '_';
       Fixup += toupper(Word.front());
       Fixup += Word.substr(1).lower();
     }
@@ -993,7 +993,7 @@ std::string IdentifierNamingCheck::fixupWithCase(
   case IdentifierNamingCheck::CT_CamelSnakeBack:
     for (const auto &Word : Words) {
       if (&Word != &Words.front()) {
-        Fixup += "_";
+        Fixup += '_';
         Fixup += toupper(Word.front());
       } else {
         Fixup += tolower(Word.front());
@@ -1005,7 +1005,7 @@ std::string IdentifierNamingCheck::fixupWithCase(
   case IdentifierNamingCheck::CT_LeadingUpperSnakeCase:
     for (const auto &Word : Words) {
       if (&Word != &Words.front()) {
-        Fixup += "_";
+        Fixup += '_';
         Fixup += Word.lower();
       } else {
         Fixup += toupper(Word.front());
@@ -1100,7 +1100,7 @@ std::string IdentifierNamingCheck::fixupWithStyle(
     HungarianPrefix = HungarianNotation.getPrefix(D, HNOption);
     if (!HungarianPrefix.empty()) {
       if (Style.HPType == HungarianPrefixType::HPT_LowerCase)
-        HungarianPrefix += "_";
+        HungarianPrefix += '_';
 
       if (Style.HPType == HungarianPrefixType::HPT_CamelCase)
         Fixed[0] = toupper(Fixed[0]);
diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index a138d1900b799..055ca6f8bdf85 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -99,9 +99,9 @@ static void fixGenericExprCastToBool(DiagnosticBuilder &Diag,
   std::string StartLocInsertion;
 
   if (NeedOuterParens)
-    StartLocInsertion += "(";
+    StartLocInsertion += '(';
   if (NeedInnerParens)
-    StartLocInsertion += "(";
+    StartLocInsertion += '(';
 
   if (!StartLocInsertion.empty())
     Diag << FixItHint::CreateInsertion(Cast->getBeginLoc(), StartLocInsertion);
@@ -109,7 +109,7 @@ static void fixGenericExprCastToBool(DiagnosticBuilder &Diag,
   std::string EndLocInsertion;
 
   if (NeedInnerParens)
-    EndLocInsertion += ")";
+    EndLocInsertion += ')';
 
   if (InvertComparison)
     EndLocInsertion += " == ";
@@ -125,7 +125,7 @@ static void fixGenericExprCastToBool(DiagnosticBuilder &Diag,
     EndLocInsertion += ZeroLiteral;
 
   if (NeedOuterParens)
-    EndLocInsertion += ")";
+    EndLocInsertion += ')';
 
   const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
       Cast->getEndLoc(), 0, Context.getSourceManager(), Context.getLangOpts());
diff --git a/clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.cpp b/clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.cpp
index 5e3f3f6777279..88a54917a5ef5 100644
--- a/clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IsolateDeclarationCheck.cpp
@@ -235,7 +235,7 @@ createIsolatedDecls(llvm::ArrayRef<StringRef> Snippets) {
 
   for (std::size_t I = 1; I < Snippets.size(); ++I)
     Decls[I - 1] = Twine(Snippets[0])
-                       .concat(Snippets[0].ends_with(" ") ? "" : " ")
+                       .concat(Snippets[0].ends_with(' ') ? "" : " ")
                        .concat(Snippets[I].ltrim())
                        .concat(";")
                        .str();
diff --git a/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp b/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp
index d8145700f5a9d..ed1af05d232ce 100644
--- a/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp
@@ -177,7 +177,7 @@ void UseStdMinMaxCheck::check(const MatchFinder::MatchResult &Result) {
       Text = Text.ltrim();
       if (!Text.empty()) {
         if (!Comment.empty())
-          Comment += " ";
+          Comment += ' ';
         Comment += Text;
       }
     };
diff --git a/clang-tools-extra/clang-tidy/utils/Matchers.h b/clang-tools-extra/clang-tidy/utils/Matchers.h
index 674f871493dfd..fea3ef041df1c 100644
--- a/clang-tools-extra/clang-tidy/utils/Matchers.h
+++ b/clang-tools-extra/clang-tidy/utils/Matchers.h
@@ -120,9 +120,9 @@ class MatchesAnyListedRegexNameMatcher
 
   private:
     MatchMode determineMatchMode(StringRef Regex) {
-      if (Regex.starts_with(":") || Regex.starts_with("^:"))
+      if (Regex.starts_with(':') || Regex.starts_with("^:"))
         return MatchMode::MatchFullyQualified;
-      return Regex.contains(":") ? MatchMode::MatchQualified
+      return Regex.contains(':') ? MatchMode::MatchQualified
                                  : MatchMode::MatchUnqualified;
     }
   };

``````````

</details>


https://github.com/llvm/llvm-project/pull/189202


More information about the cfe-commits mailing list