Skip to content

Commit 68f832f

Browse files
[clang] Use StringRef::consume_front (NFC)
1 parent 9e98f8d commit 68f832f

File tree

9 files changed

+12
-21
lines changed

9 files changed

+12
-21
lines changed

clang/lib/CodeGen/CodeGenAction.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,8 +1139,7 @@ CodeGenAction::loadModule(MemoryBufferRef MBRef) {
11391139

11401140
// Strip off a leading diagnostic code if there is one.
11411141
StringRef Msg = Err.getMessage();
1142-
if (Msg.starts_with("error: "))
1143-
Msg = Msg.substr(7);
1142+
Msg.consume_front("error: ");
11441143

11451144
unsigned DiagID =
11461145
CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2388,8 +2388,7 @@ static void GetSDLFromOffloadArchive(
23882388
FoundAOB = true;
23892389
}
23902390
} else {
2391-
if (Lib.starts_with("-l"))
2392-
Lib = Lib.drop_front(2);
2391+
Lib.consume_front("-l");
23932392
for (auto LPath : LibraryPaths) {
23942393
ArchiveOfBundles.clear();
23952394
auto LibFile = (Lib.starts_with(":") ? Lib.drop_front()

clang/lib/Frontend/DependencyGraph.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ void DependencyGraphCallback::OutputGraphFile() {
110110
writeNodeReference(OS, AllFiles[I]);
111111
OS << " [ shape=\"box\", label=\"";
112112
StringRef FileName = AllFiles[I].getName();
113-
if (FileName.starts_with(SysRoot))
114-
FileName = FileName.substr(SysRoot.size());
113+
FileName.consume_front(SysRoot);
115114

116115
OS << DOT::EscapeString(std::string(FileName)) << "\"];\n";
117116
}

clang/lib/Frontend/VerifyDiagnosticConsumer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,8 +1144,7 @@ std::unique_ptr<Directive> Directive::create(bool RegexKind,
11441144
std::string RegexStr;
11451145
StringRef S = Text;
11461146
while (!S.empty()) {
1147-
if (S.starts_with("{{")) {
1148-
S = S.drop_front(2);
1147+
if (S.consume_front("{{")) {
11491148
size_t RegexMatchLength = S.find("}}");
11501149
assert(RegexMatchLength != StringRef::npos);
11511150
// Append the regex, enclosed in parentheses.

clang/lib/Sema/SemaChecking.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,8 +1219,8 @@ void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
12191219
if (IsChkVariant) {
12201220
FunctionName = FunctionName.drop_front(std::strlen("__builtin___"));
12211221
FunctionName = FunctionName.drop_back(std::strlen("_chk"));
1222-
} else if (FunctionName.starts_with("__builtin_")) {
1223-
FunctionName = FunctionName.drop_front(std::strlen("__builtin_"));
1222+
} else {
1223+
FunctionName.consume_front("__builtin_");
12241224
}
12251225
return FunctionName;
12261226
};

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5825,8 +5825,7 @@ struct IntrinToName {
58255825
static bool ArmBuiltinAliasValid(unsigned BuiltinID, StringRef AliasName,
58265826
ArrayRef<IntrinToName> Map,
58275827
const char *IntrinNames) {
5828-
if (AliasName.starts_with("__arm_"))
5829-
AliasName = AliasName.substr(6);
5828+
AliasName.consume_front("__arm_");
58305829
const IntrinToName *It =
58315830
llvm::lower_bound(Map, BuiltinID, [](const IntrinToName &L, unsigned Id) {
58325831
return L.Id < Id;

clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ void WalkAST::VisitCallExpr(CallExpr *CE) {
140140
if (!II) // if no identifier, not a simple C function
141141
return;
142142
StringRef Name = II->getName();
143-
if (Name.starts_with("__builtin_"))
144-
Name = Name.substr(10);
143+
Name.consume_front("__builtin_");
145144

146145
// Set the evaluation function by switching on the callee name.
147146
FnCheck evalFunction =
@@ -763,8 +762,7 @@ void WalkAST::checkDeprecatedOrUnsafeBufferHandling(const CallExpr *CE,
763762
enum { DEPR_ONLY = -1, UNKNOWN_CALL = -2 };
764763

765764
StringRef Name = FD->getIdentifier()->getName();
766-
if (Name.starts_with("__builtin_"))
767-
Name = Name.substr(10);
765+
Name.consume_front("__builtin_");
768766

769767
int ArgIndex =
770768
llvm::StringSwitch<int>(Name)

clang/lib/Tooling/Refactoring/Lookup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ static StringRef getBestNamespaceSubstr(const DeclContext *DeclA,
9898
// from NewName if it has an identical prefix.
9999
std::string NS =
100100
"::" + cast<NamespaceDecl>(DeclA)->getQualifiedNameAsString() + "::";
101-
if (NewName.starts_with(NS))
102-
return NewName.substr(NS.size());
101+
if (NewName.consume_front(NS))
102+
return NewName;
103103

104104
// No match yet. Strip of a namespace from the end of the chain and try
105105
// again. This allows to get optimal qualifications even if the old and new

clang/lib/Tooling/Tooling.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,7 @@ llvm::Expected<std::string> getAbsolutePath(llvm::vfs::FileSystem &FS,
255255
StringRef File) {
256256
StringRef RelativePath(File);
257257
// FIXME: Should '.\\' be accepted on Win32?
258-
if (RelativePath.starts_with("./")) {
259-
RelativePath = RelativePath.substr(strlen("./"));
260-
}
258+
RelativePath.consume_front("./");
261259

262260
SmallString<1024> AbsolutePath = RelativePath;
263261
if (auto EC = FS.makeAbsolute(AbsolutePath))

0 commit comments

Comments
 (0)