[llvm] 5e9da33 - [llvm] Use StringRef::consume_front_insensitive (NFC)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 11 22:48:31 PST 2024


Author: Kazu Hirata
Date: 2024-01-11T22:48:20-08:00
New Revision: 5e9da33b8743d13e29be1350e357f2d527a417dd

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

LOG: [llvm] Use StringRef::consume_front_insensitive (NFC)

Added: 
    

Modified: 
    llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp
    llvm/lib/Support/StringRef.cpp
    llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
    llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp b/llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp
index 01d49709f9b29c..3528da42b12bca 100644
--- a/llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp
@@ -611,12 +611,9 @@ std::optional<std::string> MarkupFilter::parseMode(StringRef Str) const {
 
   // Pop off each of r/R, w/W, and x/X from the front, in that order.
   StringRef Remainder = Str;
-  if (!Remainder.empty() && tolower(Remainder.front()) == 'r')
-    Remainder = Remainder.drop_front();
-  if (!Remainder.empty() && tolower(Remainder.front()) == 'w')
-    Remainder = Remainder.drop_front();
-  if (!Remainder.empty() && tolower(Remainder.front()) == 'x')
-    Remainder = Remainder.drop_front();
+  Remainder.consume_front_insensitive("r");
+  Remainder.consume_front_insensitive("w");
+  Remainder.consume_front_insensitive("x");
 
   // If anything remains, then the string wasn't a mode.
   if (!Remainder.empty()) {

diff  --git a/llvm/lib/Support/StringRef.cpp b/llvm/lib/Support/StringRef.cpp
index feee47ca693b25..decd06abbeb15f 100644
--- a/llvm/lib/Support/StringRef.cpp
+++ b/llvm/lib/Support/StringRef.cpp
@@ -388,20 +388,14 @@ static unsigned GetAutoSenseRadix(StringRef &Str) {
   if (Str.empty())
     return 10;
 
-  if (Str.starts_with("0x") || Str.starts_with("0X")) {
-    Str = Str.substr(2);
+  if (Str.consume_front_insensitive("0x"))
     return 16;
-  }
 
-  if (Str.starts_with("0b") || Str.starts_with("0B")) {
-    Str = Str.substr(2);
+  if (Str.consume_front_insensitive("0b"))
     return 2;
-  }
 
-  if (Str.starts_with("0o")) {
-    Str = Str.substr(2);
+  if (Str.consume_front("0o"))
     return 8;
-  }
 
   if (Str[0] == '0' && Str.size() > 1 && isDigit(Str[1])) {
     Str = Str.substr(1);

diff  --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
index f6ea262d69e4d5..c1cb096bb66dea 100644
--- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
+++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
@@ -6894,12 +6894,7 @@ bool AArch64AsmParser::parseDirectiveArch(SMLoc L) {
   FeatureBitset Features = STI.getFeatureBits();
   setAvailableFeatures(ComputeAvailableFeatures(Features));
   for (auto Name : RequestedExtensions) {
-    bool EnableFeature = true;
-
-    if (Name.starts_with_insensitive("no")) {
-      EnableFeature = false;
-      Name = Name.substr(2);
-    }
+    bool EnableFeature = !Name.consume_front_insensitive("no");
 
     for (const auto &Extension : ExtensionMap) {
       if (Extension.Name != Name)
@@ -6990,12 +6985,7 @@ bool AArch64AsmParser::parseDirectiveCPU(SMLoc L) {
     // Advance source location past '+'.
     CurLoc = incrementLoc(CurLoc, 1);
 
-    bool EnableFeature = true;
-
-    if (Name.starts_with_insensitive("no")) {
-      EnableFeature = false;
-      Name = Name.substr(2);
-    }
+    bool EnableFeature = !Name.consume_front_insensitive("no");
 
     bool FoundExtension = false;
     for (const auto &Extension : ExtensionMap) {

diff  --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
index 18dccb26b87769..a91dd24a9056a9 100644
--- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
+++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
@@ -12668,11 +12668,7 @@ bool ARMAsmParser::enableArchExtFeature(StringRef Name, SMLoc &ExtLoc) {
       {ARM::AEK_MAVERICK, {}, {}},
       {ARM::AEK_XSCALE, {}, {}},
   };
-  bool EnableFeature = true;
-  if (Name.starts_with_insensitive("no")) {
-    EnableFeature = false;
-    Name = Name.substr(2);
-  }
+  bool EnableFeature = !Name.consume_front_insensitive("no");
   uint64_t FeatureKind = ARM::parseArchExt(Name);
   if (FeatureKind == ARM::AEK_INVALID)
     return Error(ExtLoc, "unknown architectural extension: " + Name);


        


More information about the llvm-commits mailing list