Skip to content

[lld] Use StringRef idioms (NFC) #109584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -867,8 +867,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
Loading