[llvm] 1950190 - [DebugInfo] Use StringRef::starts_with/ends_with instead of startswith/endswith. NFC.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 6 07:22:27 PST 2023
Author: Simon Pilgrim
Date: 2023-11-06T15:20:20Z
New Revision: 1950190b61e1087219a6c5157e742517b8023b76
URL: https://github.com/llvm/llvm-project/commit/1950190b61e1087219a6c5157e742517b8023b76
DIFF: https://github.com/llvm/llvm-project/commit/1950190b61e1087219a6c5157e742517b8023b76.diff
LOG: [DebugInfo] Use StringRef::starts_with/ends_with instead of startswith/endswith. NFC.
startswith/endswith wrap starts_with/ends_with and will eventually go away (to more closely match string_view)
Added:
Modified:
llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewReader.cpp
llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
llvm/lib/DebugInfo/PDB/Native/TpiHashing.cpp
llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp
llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
Removed:
################################################################################
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
index 126725f229c545d..8302cbbf231aedf 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
@@ -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.
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 57ca11a077a486a..088dffeaa2b9f6d 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -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 + "'"));
}
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp b/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
index 5a5ac28f1822115..20242d958b6b423 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
@@ -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()))
@@ -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);
@@ -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;
diff --git a/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp b/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
index d720c1e33495515..7809fd65bfc8f9d 100644
--- a/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
+++ b/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
@@ -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);
diff --git a/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewReader.cpp b/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewReader.cpp
index d1789fe587f3a5a..1f6724988ae979f 100644
--- a/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewReader.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewReader.cpp
@@ -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"))
diff --git a/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp b/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
index cddee3e1c273f56..328d0f5ab060fe1 100644
--- a/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
@@ -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;
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
index fb0ca2f9cf229c6..d5cac33d15193e5 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
@@ -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);
diff --git a/llvm/lib/DebugInfo/PDB/Native/TpiHashing.cpp b/llvm/lib/DebugInfo/PDB/Native/TpiHashing.cpp
index b71b2b15814419b..941ce78027a2136 100644
--- a/llvm/lib/DebugInfo/PDB/Native/TpiHashing.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/TpiHashing.cpp
@@ -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,
diff --git a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
index d7b33ce1d0f062d..716312f26e0bac0 100644
--- a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
@@ -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)
diff --git a/llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp b/llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp
index a2bc2577b70acb9..f7503ef49693d8d 100644
--- a/llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp
@@ -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;
}
@@ -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 {
diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
index 36d112a5f3fb299..15f2a6ece8b897d 100644
--- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
@@ -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;
}
More information about the llvm-commits
mailing list