[llvm] 18549aa - [llvm] Use StringRef::drop_back (NFC) (#139471)

via llvm-commits llvm-commits at lists.llvm.org
Sun May 11 15:37:45 PDT 2025


Author: Kazu Hirata
Date: 2025-05-11T15:37:41-07:00
New Revision: 18549aa1ccb6621ee856465d5e68982c3cc90f5f

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

LOG: [llvm] Use StringRef::drop_back (NFC) (#139471)

Added: 
    

Modified: 
    llvm/include/llvm/IR/Constants.h
    llvm/lib/Support/CommandLine.cpp
    llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h
index 76efa9bd63522..7137c699cc992 100644
--- a/llvm/include/llvm/IR/Constants.h
+++ b/llvm/include/llvm/IR/Constants.h
@@ -672,7 +672,7 @@ class ConstantDataSequential : public ConstantData {
   StringRef getAsCString() const {
     assert(isCString() && "Isn't a C string");
     StringRef Str = getAsString();
-    return Str.substr(0, Str.size() - 1);
+    return Str.drop_back();
   }
 
   /// Return the raw, underlying, bytes of this data. Note that this is an

diff  --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index f1dd39ce133a8..a407be929af85 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -726,7 +726,7 @@ static Option *getOptionPred(StringRef Name, size_t &Length,
   // characters in it (so that the next iteration will not be the empty
   // string.
   while (OMI == OptionsMap.end() && Name.size() > 1) {
-    Name = Name.substr(0, Name.size() - 1); // Chop off the last character.
+    Name = Name.drop_back();
     OMI = OptionsMap.find(Name);
     if (OMI != OptionsMap.end() && !Pred(OMI->getValue()))
       OMI = OptionsMap.end();

diff  --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp
index 7f8315529e675..91051cd4e2d51 100644
--- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp
+++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp
@@ -644,9 +644,8 @@ MCSubtargetInfo *Hexagon_MC::createHexagonMCSubtargetInfo(const Triple &TT,
 void Hexagon_MC::addArchSubtarget(MCSubtargetInfo const *STI, StringRef FS) {
   assert(STI != nullptr);
   if (STI->getCPU().contains("t")) {
-    auto ArchSTI = createHexagonMCSubtargetInfo(
-        STI->getTargetTriple(),
-        STI->getCPU().substr(0, STI->getCPU().size() - 1), FS);
+    auto ArchSTI = createHexagonMCSubtargetInfo(STI->getTargetTriple(),
+                                                STI->getCPU().drop_back(), FS);
     std::lock_guard<std::mutex> Lock(ArchSubtargetMutex);
     ArchSubtarget[std::string(STI->getCPU())] =
         std::unique_ptr<MCSubtargetInfo const>(ArchSTI);


        


More information about the llvm-commits mailing list