Skip to content

Commit ad8fd5b

Browse files
[BOLT] Use StringRef::{starts,ends}_with (NFC)
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
1 parent d5953e3 commit ad8fd5b

File tree

12 files changed

+42
-41
lines changed

12 files changed

+42
-41
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,8 +900,8 @@ class BinaryContext {
900900
/// Return true if \p SymbolName was generated internally and was not present
901901
/// in the input binary.
902902
bool isInternalSymbolName(const StringRef Name) {
903-
return Name.startswith("SYMBOLat") || Name.startswith("DATAat") ||
904-
Name.startswith("HOLEat");
903+
return Name.starts_with("SYMBOLat") || Name.starts_with("DATAat") ||
904+
Name.starts_with("HOLEat");
905905
}
906906

907907
MCSymbol *getHotTextStartSymbol() const {

bolt/lib/Core/BinaryContext.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ void BinaryContext::generateSymbolHashes() {
10861086
auto isPadding = [](const BinaryData &BD) {
10871087
StringRef Contents = BD.getSection().getContents();
10881088
StringRef SymData = Contents.substr(BD.getOffset(), BD.getSize());
1089-
return (BD.getName().startswith("HOLEat") ||
1089+
return (BD.getName().starts_with("HOLEat") ||
10901090
SymData.find_first_not_of(0) == StringRef::npos);
10911091
};
10921092

@@ -1326,8 +1326,8 @@ void BinaryContext::postProcessSymbolTable() {
13261326
bool Valid = true;
13271327
for (auto &Entry : BinaryDataMap) {
13281328
BinaryData *BD = Entry.second;
1329-
if ((BD->getName().startswith("SYMBOLat") ||
1330-
BD->getName().startswith("DATAat")) &&
1329+
if ((BD->getName().starts_with("SYMBOLat") ||
1330+
BD->getName().starts_with("DATAat")) &&
13311331
!BD->getParent() && !BD->getSize() && !BD->isAbsolute() &&
13321332
BD->getSection()) {
13331333
errs() << "BOLT-WARNING: zero-sized top level symbol: " << *BD << "\n";
@@ -1410,9 +1410,9 @@ void BinaryContext::fixBinaryDataHoles() {
14101410
auto isNotHole = [&Section](const binary_data_iterator &Itr) {
14111411
BinaryData *BD = Itr->second;
14121412
bool isHole = (!BD->getParent() && !BD->getSize() && BD->isObject() &&
1413-
(BD->getName().startswith("SYMBOLat0x") ||
1414-
BD->getName().startswith("DATAat0x") ||
1415-
BD->getName().startswith("ANONYMOUS")));
1413+
(BD->getName().starts_with("SYMBOLat0x") ||
1414+
BD->getName().starts_with("DATAat0x") ||
1415+
BD->getName().starts_with("ANONYMOUS")));
14161416
return !isHole && BD->getSection() == Section && !BD->getParent();
14171417
};
14181418

@@ -1818,14 +1818,14 @@ MarkerSymType BinaryContext::getMarkerType(const SymbolRef &Symbol) const {
18181818
if (*TypeOrError != SymbolRef::ST_Unknown)
18191819
return MarkerSymType::NONE;
18201820

1821-
if (*NameOrError == "$x" || NameOrError->startswith("$x."))
1821+
if (*NameOrError == "$x" || NameOrError->starts_with("$x."))
18221822
return MarkerSymType::CODE;
18231823

18241824
// $x<ISA>
1825-
if (isRISCV() && NameOrError->startswith("$x"))
1825+
if (isRISCV() && NameOrError->starts_with("$x"))
18261826
return MarkerSymType::CODE;
18271827

1828-
if (*NameOrError == "$d" || NameOrError->startswith("$d."))
1828+
if (*NameOrError == "$d" || NameOrError->starts_with("$d."))
18291829
return MarkerSymType::DATA;
18301830

18311831
return MarkerSymType::NONE;

bolt/lib/Core/BinaryData.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ bool BinaryData::hasNameRegex(StringRef NameRegex) const {
6565

6666
bool BinaryData::nameStartsWith(StringRef Prefix) const {
6767
for (const MCSymbol *Symbol : Symbols)
68-
if (Symbol->getName().startswith(Prefix))
68+
if (Symbol->getName().starts_with(Prefix))
6969
return true;
7070
return false;
7171
}

bolt/lib/Passes/IndirectCallPromotion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ IndirectCallPromotion::maybeGetHotJumpTableTargets(BinaryBasicBlock &BB,
460460

461461
if (AccessInfo.MemoryObject) {
462462
// Deal with bad/stale data
463-
if (!AccessInfo.MemoryObject->getName().startswith(
463+
if (!AccessInfo.MemoryObject->getName().starts_with(
464464
"JUMP_TABLE/" + Function.getOneName().str()))
465465
return JumpTableInfoType();
466466
Index =

bolt/lib/Passes/ReorderData.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,14 +408,14 @@ bool ReorderData::markUnmoveableSymbols(BinaryContext &BC,
408408
// suffix in another.
409409
auto isPrivate = [&](const BinaryData *BD) {
410410
auto Prefix = std::string("PG") + BC.AsmInfo->getPrivateGlobalPrefix();
411-
return BD->getName().startswith(Prefix.str());
411+
return BD->getName().starts_with(Prefix.str());
412412
};
413413
auto Range = BC.getBinaryDataForSection(Section);
414414
bool FoundUnmoveable = false;
415415
for (auto Itr = Range.begin(); Itr != Range.end(); ++Itr) {
416416
BinaryData *Next =
417417
std::next(Itr) != Range.end() ? std::next(Itr)->second : nullptr;
418-
if (Itr->second->getName().startswith("PG.")) {
418+
if (Itr->second->getName().starts_with("PG.")) {
419419
BinaryData *Prev =
420420
Itr != Range.begin() ? std::prev(Itr)->second : nullptr;
421421
bool PrevIsPrivate = Prev && isPrivate(Prev);

bolt/lib/Passes/ShrinkWrapping.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,12 +1416,12 @@ bool ShrinkWrapping::foldIdenticalSplitEdges() {
14161416
bool Changed = false;
14171417
for (auto Iter = BF.begin(); Iter != BF.end(); ++Iter) {
14181418
BinaryBasicBlock &BB = *Iter;
1419-
if (!BB.getName().startswith(".LSplitEdge"))
1419+
if (!BB.getName().starts_with(".LSplitEdge"))
14201420
continue;
14211421
for (BinaryBasicBlock &RBB : llvm::reverse(BF)) {
14221422
if (&RBB == &BB)
14231423
break;
1424-
if (!RBB.getName().startswith(".LSplitEdge") || !RBB.isValid() ||
1424+
if (!RBB.getName().starts_with(".LSplitEdge") || !RBB.isValid() ||
14251425
!isIdenticalSplitEdgeBB(BC, *Iter, RBB))
14261426
continue;
14271427
assert(RBB.pred_size() == 1 && "Invalid split edge BB");

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,7 @@ DataAggregator::parseMMapEvent() {
19151915
// PERF_RECORD_MMAP2 <pid>/<tid>: [<hexbase>(<hexsize>) .*]: .* <file_name>
19161916

19171917
StringRef FileName = Line.rsplit(FieldSeparator).second;
1918-
if (FileName.startswith("//") || FileName.startswith("[")) {
1918+
if (FileName.starts_with("//") || FileName.starts_with("[")) {
19191919
consumeRestOfLine();
19201920
return std::make_pair(StringRef(), ParsedInfo);
19211921
}
@@ -2168,7 +2168,7 @@ DataAggregator::getFileNameForBuildID(StringRef FileBuildID) {
21682168
continue;
21692169
}
21702170

2171-
if (IDPair->second.startswith(FileBuildID)) {
2171+
if (IDPair->second.starts_with(FileBuildID)) {
21722172
FileName = sys::path::filename(IDPair->first);
21732173
break;
21742174
}

bolt/lib/Profile/DataReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ bool hasVolatileName(const BinaryFunction &BF) {
5555
/// Return standard escaped name of the function possibly renamed by BOLT.
5656
std::string normalizeName(StringRef NameRef) {
5757
// Strip "PG." prefix used for globalized locals.
58-
NameRef = NameRef.startswith("PG.") ? NameRef.substr(2) : NameRef;
58+
NameRef = NameRef.starts_with("PG.") ? NameRef.substr(2) : NameRef;
5959
return getEscapedName(NameRef);
6060
}
6161

bolt/lib/Profile/YAMLProfileReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace bolt {
3939
bool YAMLProfileReader::isYAML(const StringRef Filename) {
4040
if (auto MB = MemoryBuffer::getFileOrSTDIN(Filename)) {
4141
StringRef Buffer = (*MB)->getBuffer();
42-
return Buffer.startswith("---\n");
42+
return Buffer.starts_with("---\n");
4343
} else {
4444
report_error(Filename, MB.getError());
4545
}

bolt/lib/Rewrite/ExecutableFileMemoryManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void ExecutableFileMemoryManager::updateSection(
120120
}
121121

122122
if (!IsCode && (SectionName == ".strtab" || SectionName == ".symtab" ||
123-
SectionName == "" || SectionName.startswith(".rela.")))
123+
SectionName == "" || SectionName.starts_with(".rela.")))
124124
return;
125125

126126
SmallVector<char, 256> Buf;
@@ -139,7 +139,7 @@ void ExecutableFileMemoryManager::updateSection(
139139
}
140140

141141
BinarySection *Section = nullptr;
142-
if (!OrgSecPrefix.empty() && SectionName.startswith(OrgSecPrefix)) {
142+
if (!OrgSecPrefix.empty() && SectionName.starts_with(OrgSecPrefix)) {
143143
// Update the original section contents.
144144
ErrorOr<BinarySection &> OrgSection =
145145
BC.getUniqueSectionByName(SectionName.substr(OrgSecPrefix.length()));

0 commit comments

Comments
 (0)