Skip to content

Commit 9ed46fb

Browse files
[lld] Use StringRef idioms (NFC) (llvm#109584)
1 parent 62f737f commit 9ed46fb

File tree

4 files changed

+4
-8
lines changed

4 files changed

+4
-8
lines changed

lld/COFF/Driver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ static std::string getOutputPath(StringRef path, bool isDll, bool isDriver) {
113113

114114
// Returns true if S matches /crtend.?\.o$/.
115115
static bool isCrtend(StringRef s) {
116-
if (!s.ends_with(".o"))
116+
if (!s.consume_back(".o"))
117117
return false;
118-
s = s.drop_back(2);
119118
if (s.ends_with("crtend"))
120119
return true;
121120
return !s.empty() && s.drop_back().ends_with("crtend");

lld/Common/DriverDispatcher.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ parseFlavorWithoutMinGW(llvm::SmallVectorImpl<const char *> &argsV) {
113113

114114
// Deduct the flavor from argv[0].
115115
StringRef arg0 = path::filename(argsV[0]);
116-
if (arg0.ends_with_insensitive(".exe"))
117-
arg0 = arg0.drop_back(4);
116+
arg0.consume_back_insensitive(".exe");
118117
Flavor f = parseProgname(arg0);
119118
if (f == Invalid) {
120119
err("lld is a generic driver.\n"

lld/ELF/Driver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,8 +866,7 @@ static StripPolicy getStrip(opt::InputArgList &args) {
866866
static uint64_t parseSectionAddress(StringRef s, opt::InputArgList &args,
867867
const opt::Arg &arg) {
868868
uint64_t va = 0;
869-
if (s.starts_with("0x"))
870-
s = s.drop_front(2);
869+
s.consume_front("0x");
871870
if (!to_integer(s, va, 16))
872871
error("invalid argument: " + arg.getAsString(args));
873872
return va;

lld/MachO/InputSection.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ std::string InputSection::getSourceLocation(uint64_t off) const {
167167
// Symbols are generally prefixed with an underscore, which is not included
168168
// in the debug information.
169169
StringRef symName = sym->getName();
170-
if (!symName.empty() && symName[0] == '_')
171-
symName = symName.substr(1);
170+
symName.consume_front("_");
172171

173172
if (std::optional<std::pair<std::string, unsigned>> fileLine =
174173
dwarf->getVariableLoc(symName))

0 commit comments

Comments
 (0)