Skip to content

Commit 4e3eebc

Browse files
[tools, utils] Use StringRef::contains (NFC)
1 parent ec2a252 commit 4e3eebc

File tree

7 files changed

+16
-18
lines changed

7 files changed

+16
-18
lines changed

llvm/tools/llvm-cov/CoverageFilters.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ bool NameCoverageFilter::matches(
2121
const coverage::CoverageMapping &,
2222
const coverage::FunctionRecord &Function) const {
2323
StringRef FuncName = Function.Name;
24-
return FuncName.find(Name) != StringRef::npos;
24+
return FuncName.contains(Name);
2525
}
2626

2727
bool NameRegexCoverageFilter::matches(

llvm/tools/llvm-profdata/llvm-profdata.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ static void parseInputFilenamesFile(MemoryBuffer *Buffer,
836836
if (SanitizedEntry.startswith("#"))
837837
continue;
838838
// If there's no comma, it's an unweighted profile.
839-
else if (SanitizedEntry.find(',') == StringRef::npos)
839+
else if (!SanitizedEntry.contains(','))
840840
addWeightedInput(WFV, {std::string(SanitizedEntry), 1});
841841
else
842842
addWeightedInput(WFV, parseWeightedFile(SanitizedEntry));
@@ -2108,9 +2108,8 @@ static int showInstrProfile(const std::string &Filename, bool ShowCounts,
21082108
if (FuncIsCS != ShowCS)
21092109
continue;
21102110
}
2111-
bool Show =
2112-
ShowAllFunctions || (!ShowFunction.empty() &&
2113-
Func.Name.find(ShowFunction) != Func.Name.npos);
2111+
bool Show = ShowAllFunctions ||
2112+
(!ShowFunction.empty() && Func.Name.contains(ShowFunction));
21142113

21152114
bool doTextFormatDump = (Show && TextFormat);
21162115

llvm/tools/llvm-profgen/PerfReader.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ bool PerfReaderBase::extractLBRStack(TraceStream &TraceIt,
449449
// Skip the leading instruction pointer.
450450
size_t Index = 0;
451451
uint64_t LeadingAddr;
452-
if (!Records.empty() && Records[0].find('/') == StringRef::npos) {
452+
if (!Records.empty() && !Records[0].contains('/')) {
453453
if (Records[0].getAsInteger(16, LeadingAddr)) {
454454
WarnInvalidLBR(TraceIt);
455455
TraceIt.advance();
@@ -862,7 +862,7 @@ bool PerfReaderBase::isLBRSample(StringRef Line) {
862862
Line.trim().split(Records, " ", 2, false);
863863
if (Records.size() < 2)
864864
return false;
865-
if (Records[1].startswith("0x") && Records[1].find('/') != StringRef::npos)
865+
if (Records[1].startswith("0x") && Records[1].contains('/'))
866866
return true;
867867
return false;
868868
}
@@ -877,7 +877,7 @@ bool PerfReaderBase::isMMap2Event(StringRef Line) {
877877

878878
// PERF_RECORD_MMAP2 does not appear at the beginning of the line
879879
// for ` perf script --show-mmap-events -i ...`
880-
return Line.find("PERF_RECORD_MMAP2") != StringRef::npos;
880+
return Line.contains("PERF_RECORD_MMAP2");
881881
}
882882

883883
// The raw hybird sample is like

llvm/tools/llvm-profgen/ProfileGenerator.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,7 @@ void ProfileGenerator::populateBodySamplesForAllFunctions(
403403

404404
static bool isOutlinedFunction(StringRef CalleeName) {
405405
// Check whether it's from hot-cold func split or coro split.
406-
return CalleeName.find(".resume") != StringRef::npos ||
407-
CalleeName.find(".cold") != StringRef::npos;
406+
return CalleeName.contains(".resume") || CalleeName.contains(".cold");
408407
}
409408

410409
StringRef ProfileGeneratorBase::getCalleeNameForOffset(uint64_t TargetOffset) {

llvm/utils/TableGen/AsmMatcherEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ bool MatchableInfo::validate(StringRef CommentDelimiter, bool IsAlias) const {
10711071
// Remove comments from the asm string. We know that the asmstring only
10721072
// has one line.
10731073
if (!CommentDelimiter.empty() &&
1074-
StringRef(AsmString).find(CommentDelimiter) != StringRef::npos)
1074+
StringRef(AsmString).contains(CommentDelimiter))
10751075
PrintFatalError(TheDef->getLoc(),
10761076
"asmstring for instruction has comment character in it, "
10771077
"mark it isCodeGenOnly");
@@ -1086,7 +1086,7 @@ bool MatchableInfo::validate(StringRef CommentDelimiter, bool IsAlias) const {
10861086
std::set<std::string> OperandNames;
10871087
for (const AsmOperand &Op : AsmOperands) {
10881088
StringRef Tok = Op.Token;
1089-
if (Tok[0] == '$' && Tok.find(':') != StringRef::npos)
1089+
if (Tok[0] == '$' && Tok.contains(':'))
10901090
PrintFatalError(TheDef->getLoc(),
10911091
"matchable with operand modifier '" + Tok +
10921092
"' not supported by asm matcher. Mark isCodeGenOnly!");

llvm/utils/TableGen/X86FoldTablesEmitter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ const ManualMapEntry ManualMapSet[] = {
7979

8080
static bool isExplicitAlign(const CodeGenInstruction *Inst) {
8181
return any_of(ExplicitAlign, [Inst](const char *InstStr) {
82-
return Inst->TheDef->getName().find(InstStr) != StringRef::npos;
82+
return Inst->TheDef->getName().contains(InstStr);
8383
});
8484
}
8585

8686
static bool isExplicitUnalign(const CodeGenInstruction *Inst) {
8787
return any_of(ExplicitUnalign, [Inst](const char *InstStr) {
88-
return Inst->TheDef->getName().find(InstStr) != StringRef::npos;
88+
return Inst->TheDef->getName().contains(InstStr);
8989
});
9090
}
9191

@@ -278,7 +278,7 @@ static inline bool hasMemoryFormat(const Record *Inst) {
278278
}
279279

280280
static inline bool isNOREXRegClass(const Record *Op) {
281-
return Op->getName().find("_NOREX") != StringRef::npos;
281+
return Op->getName().contains("_NOREX");
282282
}
283283

284284
static inline bool isRegisterOperand(const Record *Rec) {

llvm/utils/TableGen/X86RecognizableInstr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ RecognizableInstr::RecognizableInstr(DisassemblerTables &tables,
109109
// FIXME: Is there some better way to check for In64BitMode?
110110
std::vector<Record*> Predicates = Rec->getValueAsListOfDefs("Predicates");
111111
for (unsigned i = 0, e = Predicates.size(); i != e; ++i) {
112-
if (Predicates[i]->getName().find("Not64Bit") != Name.npos ||
113-
Predicates[i]->getName().find("In32Bit") != Name.npos) {
112+
if (Predicates[i]->getName().contains("Not64Bit") ||
113+
Predicates[i]->getName().contains("In32Bit")) {
114114
Is32Bit = true;
115115
break;
116116
}
117-
if (Predicates[i]->getName().find("In64Bit") != Name.npos) {
117+
if (Predicates[i]->getName().contains("In64Bit")) {
118118
Is64Bit = true;
119119
break;
120120
}

0 commit comments

Comments
 (0)