Skip to content

Commit f5f2c31

Browse files
[llvm] Use StringRef::consume_front (NFC)
1 parent 76243ad commit f5f2c31

File tree

9 files changed

+10
-23
lines changed

9 files changed

+10
-23
lines changed

llvm/lib/ExecutionEngine/Orc/Debugging/DebugInfoSupport.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ llvm::orc::createDWARFContext(LinkGraph &G) {
105105
auto SecData = getSectionData(Sec);
106106
auto Name = Sec.getName();
107107
// DWARFContext expects the section name to not start with a dot
108-
if (Name.starts_with("."))
109-
Name = Name.drop_front();
108+
Name.consume_front(".");
110109
LLVM_DEBUG(dbgs() << "Creating DWARFContext section " << Name
111110
<< " with size " << SecData.size() << "\n");
112111
DWARFSectionData[Name] =

llvm/lib/MC/WasmObjectWriter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,8 +1526,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
15261526
StringRef Name = SectionName;
15271527

15281528
// For user-defined custom sections, strip the prefix
1529-
if (Name.starts_with(".custom_section."))
1530-
Name = Name.substr(strlen(".custom_section."));
1529+
Name.consume_front(".custom_section.");
15311530

15321531
MCSymbol *Begin = Sec.getBeginSymbol();
15331532
if (Begin) {

llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -959,8 +959,7 @@ SPIRVType *SPIRVGlobalRegistry::getOrCreateSPIRVTypeByName(
959959
// N is the number of elements of the vector.
960960
Type *Ty;
961961

962-
if (TypeStr.starts_with("atomic_"))
963-
TypeStr = TypeStr.substr(strlen("atomic_"));
962+
TypeStr.consume_front("atomic_");
964963

965964
if (TypeStr.starts_with("void")) {
966965
Ty = Type::getVoidTy(Ctx);
@@ -1007,8 +1006,7 @@ SPIRVType *SPIRVGlobalRegistry::getOrCreateSPIRVTypeByName(
10071006
// Handle "typeN*" or "type vector[N]*".
10081007
bool IsPtrToVec = TypeStr.consume_back("*");
10091008

1010-
if (TypeStr.starts_with(" vector[")) {
1011-
TypeStr = TypeStr.substr(strlen(" vector["));
1009+
if (TypeStr.consume_front(" vector[")) {
10121010
TypeStr = TypeStr.substr(0, TypeStr.find(']'));
10131011
}
10141012
TypeStr.getAsInteger(10, VecElts);

llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,8 +2312,7 @@ bool X86AsmParser::ParseIntelDotOperator(IntelExprStateMachine &SM,
23122312

23132313
// Drop the optional '.'.
23142314
StringRef DotDispStr = Tok.getString();
2315-
if (DotDispStr.starts_with("."))
2316-
DotDispStr = DotDispStr.drop_front(1);
2315+
DotDispStr.consume_front(".");
23172316
StringRef TrailingDot;
23182317

23192318
// .Imm gets lexed as a real.

llvm/lib/Target/X86/X86InsertPrefetch.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ bool X86InsertPrefetch::findPrefetchInfo(const FunctionSamples *TopSamples,
135135
int64_t D = static_cast<int64_t>(S_V.second);
136136
unsigned IID = 0;
137137
for (const auto &HintType : HintTypes) {
138-
if (Name.starts_with(HintType.first)) {
139-
Name = Name.drop_front(HintType.first.size());
138+
if (Name.consume_front(HintType.first)) {
140139
IID = HintType.second;
141140
break;
142141
}

llvm/lib/TargetParser/ARMTargetParser.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,7 @@ StringRef ARM::getArchExtName(uint64_t ArchExtKind) {
348348
}
349349

350350
static bool stripNegationPrefix(StringRef &Name) {
351-
if (Name.starts_with("no")) {
352-
Name = Name.substr(2);
353-
return true;
354-
}
355-
return false;
351+
return Name.consume_front("no");
356352
}
357353

358354
StringRef ARM::getArchExtFeature(StringRef ArchExt) {

llvm/lib/TargetParser/Triple.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,8 +1208,7 @@ static VersionTuple parseVersionFromName(StringRef Name) {
12081208
VersionTuple Triple::getEnvironmentVersion() const {
12091209
StringRef EnvironmentName = getEnvironmentName();
12101210
StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
1211-
if (EnvironmentName.starts_with(EnvironmentTypeName))
1212-
EnvironmentName = EnvironmentName.substr(EnvironmentTypeName.size());
1211+
EnvironmentName.consume_front(EnvironmentTypeName);
12131212

12141213
return parseVersionFromName(EnvironmentName);
12151214
}

llvm/tools/llvm-ar/llvm-ar.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,8 +1287,7 @@ static const char *matchFlagWithArg(StringRef Expected,
12871287
ArrayRef<const char *> Args) {
12881288
StringRef Arg = *ArgIt;
12891289

1290-
if (Arg.starts_with("--"))
1291-
Arg = Arg.substr(2);
1290+
Arg.consume_front("--");
12921291

12931292
size_t len = Expected.size();
12941293
if (Arg == Expected) {

llvm/tools/llvm-diff/llvm-diff.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ static std::unique_ptr<Module> readModule(LLVMContext &Context,
4242
static void diffGlobal(DifferenceEngine &Engine, Module &L, Module &R,
4343
StringRef Name) {
4444
// Drop leading sigils from the global name.
45-
if (Name.starts_with("@"))
46-
Name = Name.substr(1);
45+
Name.consume_front("@");
4746

4847
Function *LFn = L.getFunction(Name);
4948
Function *RFn = R.getFunction(Name);

0 commit comments

Comments
 (0)