Skip to content

[mlir] Use std::string::find with std::string_view (NFC) #139683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

kazutakahirata
Copy link
Contributor

Starting with C++17, std::string::find accepts anything that can be
converted to std::string_view, including StringRef, allowing us to
avoid creating temporary instances of std::string.

Starting with C++17, std::string::find accepts anything that can be
converted to std::string_view, including StringRef, allowing us to
avoid creating temporary instances of std::string.
@llvmbot
Copy link
Member

llvmbot commented May 13, 2025

@llvm/pr-subscribers-mlir

Author: Kazu Hirata (kazutakahirata)

Changes

Starting with C++17, std::string::find accepts anything that can be
converted to std::string_view, including StringRef, allowing us to
avoid creating temporary instances of std::string.


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

1 Files Affected:

  • (modified) mlir/lib/TableGen/Predicate.cpp (+2-2)
diff --git a/mlir/lib/TableGen/Predicate.cpp b/mlir/lib/TableGen/Predicate.cpp
index e5cfc074d09f4..11afa27caf709 100644
--- a/mlir/lib/TableGen/Predicate.cpp
+++ b/mlir/lib/TableGen/Predicate.cpp
@@ -141,14 +141,14 @@ static void performSubstitutions(std::string &str,
                                  ArrayRef<Subst> substitutions) {
   // Apply all parent substitutions from innermost to outermost.
   for (const auto &subst : llvm::reverse(substitutions)) {
-    auto pos = str.find(std::string(subst.first));
+    auto pos = str.find(subst.first);
     while (pos != std::string::npos) {
       str.replace(pos, subst.first.size(), std::string(subst.second));
       // Skip the newly inserted substring, which itself may consider the
       // pattern to match.
       pos += subst.second.size();
       // Find the next possible match position.
-      pos = str.find(std::string(subst.first), pos);
+      pos = str.find(subst.first, pos);
     }
   }
 }

@kazutakahirata kazutakahirata merged commit 29a4561 into llvm:main May 13, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_StringRef_find_mlir branch May 13, 2025 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants