[llvm] b5d6ea4 - [Support] Use StringRef::consume_front (NFC)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 13 18:18:59 PST 2024


Author: Kazu Hirata
Date: 2024-01-13T18:18:49-08:00
New Revision: b5d6ea4d8b195558f1b79970368b185d232754d9

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

LOG: [Support] Use StringRef::consume_front (NFC)

Added: 
    

Modified: 
    llvm/lib/Support/CommandLine.cpp
    llvm/lib/Support/FormatVariadic.cpp
    llvm/lib/Support/VersionTuple.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index 553669ce8ee37c..cb9eb9183f73ea 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -1630,10 +1630,8 @@ bool CommandLineParser::ParseCommandLineOptions(int argc,
       // otherwise feed it to the eating positional.
       ArgName = StringRef(argv[i] + 1);
       // Eat second dash.
-      if (!ArgName.empty() && ArgName[0] == '-') {
+      if (ArgName.consume_front("-"))
         HaveDoubleDash = true;
-        ArgName = ArgName.substr(1);
-      }
 
       Handler = LookupLongOption(*ChosenSubCommand, ArgName, Value,
                                  LongOptionsUseDoubleDash, HaveDoubleDash);
@@ -1644,10 +1642,8 @@ bool CommandLineParser::ParseCommandLineOptions(int argc,
     } else { // We start with a '-', must be an argument.
       ArgName = StringRef(argv[i] + 1);
       // Eat second dash.
-      if (!ArgName.empty() && ArgName[0] == '-') {
+      if (ArgName.consume_front("-"))
         HaveDoubleDash = true;
-        ArgName = ArgName.substr(1);
-      }
 
       Handler = LookupLongOption(*ChosenSubCommand, ArgName, Value,
                                  LongOptionsUseDoubleDash, HaveDoubleDash);

diff  --git a/llvm/lib/Support/FormatVariadic.cpp b/llvm/lib/Support/FormatVariadic.cpp
index 10de7f16dcf870..7bbc80e14c9f76 100644
--- a/llvm/lib/Support/FormatVariadic.cpp
+++ b/llvm/lib/Support/FormatVariadic.cpp
@@ -72,8 +72,7 @@ formatv_object_base::parseReplacementItem(StringRef Spec) {
     return ReplacementItem{};
   }
   RepString = RepString.trim();
-  if (!RepString.empty() && RepString.front() == ',') {
-    RepString = RepString.drop_front();
+  if (RepString.consume_front(",")) {
     if (!consumeFieldLayout(RepString, Where, Align, Pad))
       assert(false && "Invalid replacement field layout specification!");
   }

diff  --git a/llvm/lib/Support/VersionTuple.cpp b/llvm/lib/Support/VersionTuple.cpp
index c0e007215a5dde..a4224f23b2f94f 100644
--- a/llvm/lib/Support/VersionTuple.cpp
+++ b/llvm/lib/Support/VersionTuple.cpp
@@ -85,9 +85,8 @@ bool VersionTuple::tryParse(StringRef input) {
   }
 
   // If we're not done, parse the micro version, \.[0-9]+
-  if (input[0] != '.')
+  if (!input.consume_front("."))
     return true;
-  input = input.substr(1);
   if (parseInt(input, micro))
     return true;
 
@@ -97,9 +96,8 @@ bool VersionTuple::tryParse(StringRef input) {
   }
 
   // If we're not done, parse the micro version, \.[0-9]+
-  if (input[0] != '.')
+  if (!input.consume_front("."))
     return true;
-  input = input.substr(1);
   if (parseInt(input, build))
     return true;
 


        


More information about the llvm-commits mailing list