Skip to content

Commit

Permalink
[DebugInfo] Use StringRef::starts_with/ends_with instead of startswit…
Browse files Browse the repository at this point in the history
…h/endswith. NFC.

startswith/endswith wrap starts_with/ends_with and will eventually go away (to more closely match string_view)
  • Loading branch information
RKSimon committed Nov 6, 2023
1 parent 68b071d commit 1950190
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ std::optional<StringRef> llvm::StripTemplateParameters(StringRef Name) {
//
// We look for > at the end but if it does not contain any < then we
// have something like operator>>. We check for the operator<=> case.
if (!Name.endswith(">") || Name.count("<") == 0 || Name.endswith("<=>"))
if (!Name.ends_with(">") || Name.count("<") == 0 || Name.ends_with("<=>"))
return {};

// How many < until we have the start of the template parameters.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2204,7 +2204,7 @@ class DWARFObjInMemory final : public DWARFObject {
continue;

if (!Section.relocations().empty() && Name.ends_with(".dwo") &&
RelSecName.startswith(".debug")) {
RelSecName.starts_with(".debug")) {
HandleWarning(createError("unexpected relocations for dwo section '" +
RelSecName + "'"));
}
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void DWARFTypePrinter::appendTypeTagName(dwarf::Tag T) {
StringRef TagStr = TagString(T);
static constexpr StringRef Prefix = "DW_TAG_";
static constexpr StringRef Suffix = "_type";
if (!TagStr.startswith(Prefix) || !TagStr.endswith(Suffix))
if (!TagStr.starts_with(Prefix) || !TagStr.ends_with(Suffix))
return;
OS << TagStr.substr(Prefix.size(),
TagStr.size() - (Prefix.size() + Suffix.size()))
Expand Down Expand Up @@ -181,7 +181,7 @@ DWARFTypePrinter::appendUnqualifiedNameBefore(DWARFDie D,
Word = true;
StringRef Name = NamePtr;
static constexpr StringRef MangledPrefix = "_STN|";
if (Name.startswith(MangledPrefix)) {
if (Name.starts_with(MangledPrefix)) {
Name = Name.drop_front(MangledPrefix.size());
auto Separator = Name.find('|');
assert(Separator != StringRef::npos);
Expand All @@ -191,12 +191,12 @@ DWARFTypePrinter::appendUnqualifiedNameBefore(DWARFDie D,
*OriginalFullName = (BaseName + TemplateArgs).str();
Name = BaseName;
} else
EndedWithTemplate = Name.endswith(">");
EndedWithTemplate = Name.ends_with(">");
OS << Name;
// This check would be insufficient for operator overloads like
// "operator>>" - but for now Clang doesn't try to simplify them, so this
// is OK. Add more nuanced operator overload handling here if/when needed.
if (Name.endswith(">"))
if (Name.ends_with(">"))
break;
if (!appendTemplateParameters(D))
break;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ getQualifiedNameIndex(DWARFDie &Die, uint64_t Language, GsymCreator &Gsym) {
// Some GCC optimizations create functions with names ending with .isra.<num>
// or .part.<num> and those names are just DW_AT_name, not DW_AT_linkage_name
// If it looks like it could be the case, don't add any prefix
if (ShortName.startswith("_Z") &&
if (ShortName.starts_with("_Z") &&
(ShortName.contains(".isra.") || ShortName.contains(".part.")))
return Gsym.insertString(ShortName, /* Copy */ false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ bool LVCodeViewReader::isSystemEntry(LVElement *Element, StringRef Name) const {
return StringRef::npos != Name.find(String);
};
auto Starts = [=](const char *Pattern) -> bool {
return Name.startswith(Pattern);
return Name.starts_with(Pattern);
};
auto CheckExclude = [&]() -> bool {
if (Starts("__") || Starts("_PMD") || Starts("_PMFN"))
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ static bool isMyCode(const SymbolGroup &Group) {
return true;

StringRef Name = Group.name();
if (Name.startswith("Import:"))
if (Name.starts_with("Import:"))
return false;
if (Name.ends_with_insensitive(".dll"))
return false;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ NativeSession::searchForPdb(const PdbSearchOptions &Opts) {
if (!PathOrErr)
return PathOrErr.takeError();
StringRef PathFromExe = PathOrErr.get();
sys::path::Style Style = PathFromExe.startswith("/")
sys::path::Style Style = PathFromExe.starts_with("/")
? sys::path::Style::posix
: sys::path::Style::windows;
StringRef PdbName = sys::path::filename(PathFromExe, Style);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/PDB/Native/TpiHashing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using namespace llvm::pdb;
// Corresponds to `fUDTAnon`.
static bool isAnonymous(StringRef Name) {
return Name == "<unnamed-tag>" || Name == "__unnamed" ||
Name.endswith("::<unnamed-tag>") || Name.endswith("::__unnamed");
Name.ends_with("::<unnamed-tag>") || Name.ends_with("::__unnamed");
}

// Computes the hash for a user-defined type record. This could be a struct,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class SourceCode {
size_t PosEnd = PrunedSource->find('\n', Pos);
StringRef String = PrunedSource->substr(
Pos, (PosEnd == StringRef::npos) ? StringRef::npos : (PosEnd - Pos));
if (String.endswith("\r"))
if (String.ends_with("\r"))
String = String.drop_back(1);
OS << format_decimal(L, MaxLineNumberWidth);
if (L == Line)
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ std::optional<uint64_t> MarkupFilter::parseAddr(StringRef Str) const {
}
if (all_of(Str, [](char C) { return C == '0'; }))
return 0;
if (!Str.startswith("0x")) {
if (!Str.starts_with("0x")) {
reportTypeError(Str, "address");
return std::nullopt;
}
Expand Down Expand Up @@ -741,7 +741,7 @@ uint64_t MarkupFilter::adjustAddr(uint64_t Addr, PCType Type) const {
}

StringRef MarkupFilter::lineEnding() const {
return Line.endswith("\r\n") ? "\r\n" : "\n";
return Line.ends_with("\r\n") ? "\r\n" : "\n";
}

bool MarkupFilter::MMap::contains(uint64_t Addr) const {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ StringRef demanglePE32ExternCFunc(StringRef SymbolName) {

// Remove any ending '@' for vectorcall.
bool IsVectorCall = false;
if (HasAtNumSuffix && SymbolName.endswith("@")) {
if (HasAtNumSuffix && SymbolName.ends_with("@")) {
SymbolName = SymbolName.drop_back();
IsVectorCall = true;
}
Expand Down

0 comments on commit 1950190

Please sign in to comment.