Skip to content

[mlir] Prefer StringRef::substr to slice (NFC) #113788

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

I'm planning to migrate StringRef to std::string_view
eventually. Since std::string_view does not have slice, this patch
migrates:

slice(0, N) to substr(0, N)
slice(N, StringRef::npos) to substr(N)

I'm planning to migrate StringRef to std::string_view
eventually.  Since std::string_view does not have slice, this patch
migrates:

  slice(0, N)                to  substr(0, N)
  slice(N, StringRef::npos)  to  substr(N)
@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Oct 27, 2024
@kazutakahirata kazutakahirata requested a review from kuhar October 27, 2024 03:39
@llvmbot
Copy link
Member

llvmbot commented Oct 27, 2024

@llvm/pr-subscribers-mlir

Author: Kazu Hirata (kazutakahirata)

Changes

I'm planning to migrate StringRef to std::string_view
eventually. Since std::string_view does not have slice, this patch
migrates:

slice(0, N) to substr(0, N)
slice(N, StringRef::npos) to substr(N)


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

2 Files Affected:

  • (modified) mlir/include/mlir/Support/IndentedOstream.h (+1-2)
  • (modified) mlir/lib/Query/QueryParser.cpp (+2-2)
diff --git a/mlir/include/mlir/Support/IndentedOstream.h b/mlir/include/mlir/Support/IndentedOstream.h
index 101aa8b631d299..eeab36806c4ee7 100644
--- a/mlir/include/mlir/Support/IndentedOstream.h
+++ b/mlir/include/mlir/Support/IndentedOstream.h
@@ -166,8 +166,7 @@ inline void mlir::raw_indented_ostream::write_impl(const char *ptr,
       break;
     }
 
-    auto split =
-        std::make_pair(str.slice(0, idx), str.slice(idx + 1, StringRef::npos));
+    auto split = std::make_pair(str.substr(0, idx), str.substr(idx + 1));
     // Print empty new line without spaces if line only has spaces and no extra
     // prefix is requested.
     if (!split.first.ltrim().empty() || !currentExtraPrefix.empty())
diff --git a/mlir/lib/Query/QueryParser.cpp b/mlir/lib/Query/QueryParser.cpp
index 13ee931cc5227f..31aead7d403d0d 100644
--- a/mlir/lib/Query/QueryParser.cpp
+++ b/mlir/lib/Query/QueryParser.cpp
@@ -181,8 +181,8 @@ QueryRef QueryParser::doParse() {
     if (!matcher) {
       return makeInvalidQueryFromDiagnostics(diag);
     }
-    auto actualSource = origMatcherSource.slice(0, origMatcherSource.size() -
-                                                       matcherSource.size());
+    auto actualSource = origMatcherSource.substr(0, origMatcherSource.size() -
+                                                        matcherSource.size());
     QueryRef query = new MatchQuery(actualSource, *matcher);
     query->remainingContent = matcherSource;
     return query;

@llvmbot
Copy link
Member

llvmbot commented Oct 27, 2024

@llvm/pr-subscribers-mlir-core

Author: Kazu Hirata (kazutakahirata)

Changes

I'm planning to migrate StringRef to std::string_view
eventually. Since std::string_view does not have slice, this patch
migrates:

slice(0, N) to substr(0, N)
slice(N, StringRef::npos) to substr(N)


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

2 Files Affected:

  • (modified) mlir/include/mlir/Support/IndentedOstream.h (+1-2)
  • (modified) mlir/lib/Query/QueryParser.cpp (+2-2)
diff --git a/mlir/include/mlir/Support/IndentedOstream.h b/mlir/include/mlir/Support/IndentedOstream.h
index 101aa8b631d299..eeab36806c4ee7 100644
--- a/mlir/include/mlir/Support/IndentedOstream.h
+++ b/mlir/include/mlir/Support/IndentedOstream.h
@@ -166,8 +166,7 @@ inline void mlir::raw_indented_ostream::write_impl(const char *ptr,
       break;
     }
 
-    auto split =
-        std::make_pair(str.slice(0, idx), str.slice(idx + 1, StringRef::npos));
+    auto split = std::make_pair(str.substr(0, idx), str.substr(idx + 1));
     // Print empty new line without spaces if line only has spaces and no extra
     // prefix is requested.
     if (!split.first.ltrim().empty() || !currentExtraPrefix.empty())
diff --git a/mlir/lib/Query/QueryParser.cpp b/mlir/lib/Query/QueryParser.cpp
index 13ee931cc5227f..31aead7d403d0d 100644
--- a/mlir/lib/Query/QueryParser.cpp
+++ b/mlir/lib/Query/QueryParser.cpp
@@ -181,8 +181,8 @@ QueryRef QueryParser::doParse() {
     if (!matcher) {
       return makeInvalidQueryFromDiagnostics(diag);
     }
-    auto actualSource = origMatcherSource.slice(0, origMatcherSource.size() -
-                                                       matcherSource.size());
+    auto actualSource = origMatcherSource.substr(0, origMatcherSource.size() -
+                                                        matcherSource.size());
     QueryRef query = new MatchQuery(actualSource, *matcher);
     query->remainingContent = matcherSource;
     return query;

@kazutakahirata kazutakahirata requested a review from d0k October 27, 2024 06:31
@kazutakahirata kazutakahirata merged commit 5287a9b into llvm:main Oct 27, 2024
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_StringRef_slice_mlir branch October 27, 2024 14:28
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
I'm planning to migrate StringRef to std::string_view
eventually.  Since std::string_view does not have slice, this patch
migrates:

  slice(0, N)                to  substr(0, N)
  slice(N, StringRef::npos)  to  substr(N)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:core MLIR Core Infrastructure mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants