diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 1b94f10acf80e5..f66fe3cab5a2f0 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 f5c8bcdef4e0f0..fe18c320983fa2 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 14188f98cfef33..5c2f3a60430321 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 64c584920defba..c1b3297f321f1e 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))