[Mlir-commits] [mlir] abaa79b - [mlir] Use StringRef::ltrim (NFC)

Kazu Hirata llvmlistbot at llvm.org
Mon Jan 8 21:49:39 PST 2024


Author: Kazu Hirata
Date: 2024-01-08T21:49:32-08:00
New Revision: abaa79b25dde740d5b54adab463432bee2840c85

URL: https://github.com/llvm/llvm-project/commit/abaa79b25dde740d5b54adab463432bee2840c85
DIFF: https://github.com/llvm/llvm-project/commit/abaa79b25dde740d5b54adab463432bee2840c85.diff

LOG: [mlir] Use StringRef::ltrim (NFC)

Added: 
    

Modified: 
    mlir/lib/Query/Matcher/Parser.cpp
    mlir/lib/Query/QueryParser.cpp
    mlir/lib/TableGen/Class.cpp
    mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Query/Matcher/Parser.cpp b/mlir/lib/Query/Matcher/Parser.cpp
index 6585b5d740f626..30eb4801fc03c1 100644
--- a/mlir/lib/Query/Matcher/Parser.cpp
+++ b/mlir/lib/Query/Matcher/Parser.cpp
@@ -201,10 +201,7 @@ class Parser::CodeTokenizer {
   }
 
   // Consume all leading whitespace from code, except newlines
-  void consumeWhitespace() {
-    code = code.drop_while(
-        [](char c) { return llvm::StringRef(" \t\v\f\r").contains(c); });
-  }
+  void consumeWhitespace() { code = code.ltrim(" \t\v\f\r"); }
 
   // Returns the current location in the source code
   SourceLocation currentLocation() {

diff  --git a/mlir/lib/Query/QueryParser.cpp b/mlir/lib/Query/QueryParser.cpp
index f43a28569f0078..595055a42965ff 100644
--- a/mlir/lib/Query/QueryParser.cpp
+++ b/mlir/lib/Query/QueryParser.cpp
@@ -16,10 +16,8 @@ namespace mlir::query {
 // is found before end, return StringRef(). begin is adjusted to exclude the
 // lexed region.
 llvm::StringRef QueryParser::lexWord() {
-  line = line.drop_while([](char c) {
-    // Don't trim newlines.
-    return llvm::StringRef(" \t\v\f\r").contains(c);
-  });
+  // Don't trim newlines.
+  line = line.ltrim(" \t\v\f\r");
 
   if (line.empty())
     // Even though the line is empty, it contains a pointer and
@@ -91,8 +89,7 @@ struct QueryParser::LexOrCompleteWord {
 
 QueryRef QueryParser::endQuery(QueryRef queryRef) {
   llvm::StringRef extra = line;
-  llvm::StringRef extraTrimmed = extra.drop_while(
-      [](char c) { return llvm::StringRef(" \t\v\f\r").contains(c); });
+  llvm::StringRef extraTrimmed = extra.ltrim(" \t\v\f\r");
 
   if ((!extraTrimmed.empty() && extraTrimmed[0] == '\n') ||
       (extraTrimmed.size() >= 2 && extraTrimmed[0] == '\r' &&

diff  --git a/mlir/lib/TableGen/Class.cpp b/mlir/lib/TableGen/Class.cpp
index f71d7e07ed4998..9092adcc627c08 100644
--- a/mlir/lib/TableGen/Class.cpp
+++ b/mlir/lib/TableGen/Class.cpp
@@ -113,7 +113,7 @@ MethodBody::MethodBody(bool declOnly)
     : declOnly(declOnly), stringOs(body), os(stringOs) {}
 
 void MethodBody::writeTo(raw_indented_ostream &os) const {
-  auto bodyRef = StringRef(body).drop_while([](char c) { return c == '\n'; });
+  auto bodyRef = StringRef(body).ltrim('\n');
   os << bodyRef;
   if (bodyRef.empty())
     return;

diff  --git a/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp b/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp
index f8d348aba5a3cc..f1a362385f2850 100644
--- a/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp
+++ b/mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp
@@ -103,7 +103,7 @@ lsp::extractSourceDocComment(llvm::SourceMgr &sourceMgr, SMLoc loc) {
       break;
 
     // Extract the document string from the comment.
-    commentLines.push_back(line->drop_while([](char c) { return c == '/'; }));
+    commentLines.push_back(line->ltrim('/'));
   }
 
   if (commentLines.empty())


        


More information about the Mlir-commits mailing list