Skip to content

Commit 64f53db

Browse files
[clang] Use StringRef::consume_front (NFC) (llvm#139472)
1 parent 18549aa commit 64f53db

File tree

4 files changed

+5
-13
lines changed

4 files changed

+5
-13
lines changed

clang/lib/CodeGen/CGBlocks.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ CGBlockInfo::CGBlockInfo(const BlockDecl *block, StringRef name)
4040

4141
// Skip asm prefix, if any. 'name' is usually taken directly from
4242
// the mangled name of the enclosing function.
43-
if (!name.empty() && name[0] == '\01')
44-
name = name.substr(1);
43+
name.consume_front("\01");
4544
}
4645

4746
// Anchor the vtable to this translation unit.

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4500,8 +4500,7 @@ void CGDebugInfo::emitFunctionStart(GlobalDecl GD, SourceLocation Loc,
45004500

45014501
Flags |= llvm::DINode::FlagPrototyped;
45024502
}
4503-
if (Name.starts_with("\01"))
4504-
Name = Name.substr(1);
4503+
Name.consume_front("\01");
45054504

45064505
assert((!D || !isa<VarDecl>(D) ||
45074506
GD.getDynamicInitKind() != DynamicInitKind::NoStub) &&
@@ -4590,8 +4589,7 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,
45904589
} else {
45914590
llvm_unreachable("not a function or ObjC method");
45924591
}
4593-
if (!Name.empty() && Name[0] == '\01')
4594-
Name = Name.substr(1);
4592+
Name.consume_front("\01");
45954593

45964594
if (D->isImplicit()) {
45974595
Flags |= llvm::DINode::FlagArtificial;

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,8 +3388,7 @@ LValue CodeGenFunction::EmitPredefinedLValue(const PredefinedExpr *E) {
33883388
auto SL = E->getFunctionName();
33893389
assert(SL != nullptr && "No StringLiteral name in PredefinedExpr");
33903390
StringRef FnName = CurFn->getName();
3391-
if (FnName.starts_with("\01"))
3392-
FnName = FnName.substr(1);
3391+
FnName.consume_front("\01");
33933392
StringRef NameItems[] = {
33943393
PredefinedExpr::getIdentKindName(E->getIdentKind()), FnName};
33953394
std::string GVName = llvm::join(NameItems, NameItems + 2, ".");

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4061,11 +4061,7 @@ namespace {
40614061
return false;
40624062
std::string BuiltinNameStr = BI.getName(BuiltinID);
40634063
StringRef BuiltinName = BuiltinNameStr;
4064-
if (BuiltinName.starts_with("__builtin_") &&
4065-
Name == BuiltinName.slice(strlen("__builtin_"), StringRef::npos)) {
4066-
return true;
4067-
}
4068-
return false;
4064+
return BuiltinName.consume_front("__builtin_") && Name == BuiltinName;
40694065
}
40704066

40714067
bool VisitStmt(const Stmt *S) {

0 commit comments

Comments
 (0)