From 18549aa1ccb6621ee856465d5e68982c3cc90f5f Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 11 May 2025 15:37:41 -0700 Subject: [PATCH] [llvm] Use StringRef::drop_back (NFC) (#139471) --- llvm/include/llvm/IR/Constants.h | 2 +- llvm/lib/Support/CommandLine.cpp | 2 +- llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h index 76efa9bd6352..7137c699cc99 100644 --- a/llvm/include/llvm/IR/Constants.h +++ b/llvm/include/llvm/IR/Constants.h @@ -672,7 +672,7 @@ public: 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 f1dd39ce133a..a407be929af8 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 7f8315529e67..91051cd4e2d5 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 Lock(ArchSubtargetMutex); ArchSubtarget[std::string(STI->getCPU())] = std::unique_ptr(ArchSTI);