[Mlir-commits] [clang-tools-extra] [llvm] [mlir] Use StringRef::starts_with (NFC) (PR #94886)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Jun 8 20:27:33 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
@llvm/pr-subscribers-mlir
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/94886.diff
3 Files Affected:
- (modified) bolt/lib/Profile/BoltAddressTranslation.cpp (+1-1)
- (modified) clang-tools-extra/clang-query/QueryParser.cpp (+2-4)
- (modified) mlir/lib/Query/QueryParser.cpp (+2-4)
``````````diff
diff --git a/bolt/lib/Profile/BoltAddressTranslation.cpp b/bolt/lib/Profile/BoltAddressTranslation.cpp
index cdfca2b9871ac..519f282a2351c 100644
--- a/bolt/lib/Profile/BoltAddressTranslation.cpp
+++ b/bolt/lib/Profile/BoltAddressTranslation.cpp
@@ -304,7 +304,7 @@ std::error_code BoltAddressTranslation::parse(raw_ostream &OS, StringRef Buf) {
StringRef Name = Buf.slice(Offset, Offset + NameSz);
Offset = alignTo(Offset + NameSz, 4);
- if (Name.substr(0, 4) != "BOLT")
+ if (!Name.starts_with("BOLT"))
return make_error_code(llvm::errc::io_error);
Error Err(Error::success());
diff --git a/clang-tools-extra/clang-query/QueryParser.cpp b/clang-tools-extra/clang-query/QueryParser.cpp
index 1d0b7d9bc6fc8..97cb264a611af 100644
--- a/clang-tools-extra/clang-query/QueryParser.cpp
+++ b/clang-tools-extra/clang-query/QueryParser.cpp
@@ -144,13 +144,11 @@ QueryRef QueryParser::endQuery(QueryRef Q) {
StringRef Extra = Line;
StringRef ExtraTrimmed = Extra.ltrim(" \t\v\f\r");
- if ((!ExtraTrimmed.empty() && ExtraTrimmed[0] == '\n') ||
- (ExtraTrimmed.size() >= 2 && ExtraTrimmed[0] == '\r' &&
- ExtraTrimmed[1] == '\n'))
+ if (ExtraTrimmed.starts_with('\n') || ExtraTrimmed.starts_with("\r\n"))
Q->RemainingContent = Extra;
else {
StringRef TrailingWord = lexWord();
- if (!TrailingWord.empty() && TrailingWord.front() == '#') {
+ if (TrailingWord.starts_with('#')) {
Line = Line.drop_until([](char c) { return c == '\n'; });
Line = Line.drop_while([](char c) { return c == '\n'; });
return endQuery(Q);
diff --git a/mlir/lib/Query/QueryParser.cpp b/mlir/lib/Query/QueryParser.cpp
index 595055a42965f..8a034634c5b89 100644
--- a/mlir/lib/Query/QueryParser.cpp
+++ b/mlir/lib/Query/QueryParser.cpp
@@ -91,13 +91,11 @@ QueryRef QueryParser::endQuery(QueryRef queryRef) {
llvm::StringRef extra = line;
llvm::StringRef extraTrimmed = extra.ltrim(" \t\v\f\r");
- if ((!extraTrimmed.empty() && extraTrimmed[0] == '\n') ||
- (extraTrimmed.size() >= 2 && extraTrimmed[0] == '\r' &&
- extraTrimmed[1] == '\n'))
+ if (extraTrimmed.starts_with('\n') || extraTrimmed.starts_with("\r\n"))
queryRef->remainingContent = extra;
else {
llvm::StringRef trailingWord = lexWord();
- if (!trailingWord.empty() && trailingWord.front() == '#') {
+ if (trailingWord.starts_with('#')) {
line = line.drop_until([](char c) { return c == '\n'; });
line = line.drop_while([](char c) { return c == '\n'; });
return endQuery(queryRef);
``````````
</details>
https://github.com/llvm/llvm-project/pull/94886
More information about the Mlir-commits
mailing list