From 9ed46fbe9fa153316b7b0bb0906f3c8db45a8f81 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 22 Sep 2024 20:45:25 -0700 Subject: [PATCH] [lld] Use StringRef idioms (NFC) (#109584) --- lld/COFF/Driver.cpp | 3 +-- lld/Common/DriverDispatcher.cpp | 3 +-- lld/ELF/Driver.cpp | 3 +-- lld/MachO/InputSection.cpp | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 1b94f10acf80e51..f66fe3cab5a2f04 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -113,9 +113,8 @@ static std::string getOutputPath(StringRef path, bool isDll, bool isDriver) { // Returns true if S matches /crtend.?\.o$/. static bool isCrtend(StringRef s) { - if (!s.ends_with(".o")) + if (!s.consume_back(".o")) return false; - s = s.drop_back(2); if (s.ends_with("crtend")) return true; return !s.empty() && s.drop_back().ends_with("crtend"); diff --git a/lld/Common/DriverDispatcher.cpp b/lld/Common/DriverDispatcher.cpp index f5c8bcdef4e0f09..fe18c320983fa26 100644 --- a/lld/Common/DriverDispatcher.cpp +++ b/lld/Common/DriverDispatcher.cpp @@ -113,8 +113,7 @@ parseFlavorWithoutMinGW(llvm::SmallVectorImpl &argsV) { // Deduct the flavor from argv[0]. StringRef arg0 = path::filename(argsV[0]); - if (arg0.ends_with_insensitive(".exe")) - arg0 = arg0.drop_back(4); + arg0.consume_back_insensitive(".exe"); Flavor f = parseProgname(arg0); if (f == Invalid) { err("lld is a generic driver.\n" diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 14188f98cfef33a..5c2f3a604303217 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -866,8 +866,7 @@ static StripPolicy getStrip(opt::InputArgList &args) { static uint64_t parseSectionAddress(StringRef s, opt::InputArgList &args, const opt::Arg &arg) { uint64_t va = 0; - if (s.starts_with("0x")) - s = s.drop_front(2); + s.consume_front("0x"); if (!to_integer(s, va, 16)) error("invalid argument: " + arg.getAsString(args)); return va; diff --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp index 64c584920defbac..c1b3297f321f1eb 100644 --- a/lld/MachO/InputSection.cpp +++ b/lld/MachO/InputSection.cpp @@ -167,8 +167,7 @@ std::string InputSection::getSourceLocation(uint64_t off) const { // Symbols are generally prefixed with an underscore, which is not included // in the debug information. StringRef symName = sym->getName(); - if (!symName.empty() && symName[0] == '_') - symName = symName.substr(1); + symName.consume_front("_"); if (std::optional> fileLine = dwarf->getVariableLoc(symName))