Skip to content

Commit

Permalink
[lld] Use StringRef idioms (NFC) (#109584)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata authored Sep 23, 2024
1 parent 62f737f commit 9ed46fb
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 8 deletions.
3 changes: 1 addition & 2 deletions lld/COFF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 1 addition & 2 deletions lld/Common/DriverDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ parseFlavorWithoutMinGW(llvm::SmallVectorImpl<const char *> &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"
Expand Down
3 changes: 1 addition & 2 deletions lld/ELF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions lld/MachO/InputSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<std::string, unsigned>> fileLine =
dwarf->getVariableLoc(symName))
Expand Down

0 comments on commit 9ed46fb

Please sign in to comment.