Skip to content

Commit b67ce7e

Browse files
[clang] Use StringRef::starts_with (NFC)
1 parent 39fa304 commit b67ce7e

File tree

5 files changed

+6
-9
lines changed

5 files changed

+6
-9
lines changed

clang/lib/AST/TypePrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2264,7 +2264,7 @@ printTo(raw_ostream &OS, ArrayRef<TA> Args, const PrintingPolicy &Policy,
22642264
// If this is the first argument and its string representation
22652265
// begins with the global scope specifier ('::foo'), add a space
22662266
// to avoid printing the diagraph '<:'.
2267-
if (FirstArg && !ArgString.empty() && ArgString[0] == ':')
2267+
if (FirstArg && ArgString.starts_with(":"))
22682268
OS << ' ';
22692269

22702270
OS << ArgString;

clang/lib/Basic/Targets/X86.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ bool X86TargetInfo::initFeatureMap(
151151
// Postpone AVX10 features handling after AVX512 settled.
152152
UpdatedAVX10FeaturesVec.push_back(Feature);
153153
continue;
154-
} else if (!HasAVX512F && Feature.substr(0, 7) == "+avx512") {
154+
} else if (!HasAVX512F && StringRef(Feature).starts_with("+avx512")) {
155155
HasAVX512F = true;
156156
LastAVX512 = Feature;
157157
} else if (HasAVX512F && Feature == "-avx512f") {

clang/lib/CodeGen/CGObjCMac.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5038,12 +5038,10 @@ std::string CGObjCCommonMac::GetSectionName(StringRef Section,
50385038
return ("__DATA," + Section + "," + MachOAttributes).str();
50395039
}
50405040
case llvm::Triple::ELF:
5041-
assert(Section.substr(0, 2) == "__" &&
5042-
"expected the name to begin with __");
5041+
assert(Section.starts_with("__") && "expected the name to begin with __");
50435042
return Section.substr(2).str();
50445043
case llvm::Triple::COFF:
5045-
assert(Section.substr(0, 2) == "__" &&
5046-
"expected the name to begin with __");
5044+
assert(Section.starts_with("__") && "expected the name to begin with __");
50475045
return ("." + Section.substr(2) + "$B").str();
50485046
case llvm::Triple::Wasm:
50495047
case llvm::Triple::GOFF:

clang/lib/Format/FormatTokenLexer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ void FormatTokenLexer::readRawToken(FormatToken &Tok) {
14201420
// For formatting, treat unterminated string literals like normal string
14211421
// literals.
14221422
if (Tok.is(tok::unknown)) {
1423-
if (!Tok.TokenText.empty() && Tok.TokenText[0] == '"') {
1423+
if (Tok.TokenText.starts_with("\"")) {
14241424
Tok.Tok.setKind(tok::string_literal);
14251425
Tok.IsUnterminatedLiteral = true;
14261426
} else if (Style.isJavaScript() && Tok.TokenText == "''") {

clang/lib/Frontend/FrontendActions.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,8 +826,7 @@ void DumpModuleInfoAction::ExecuteAction() {
826826
auto &FileMgr = CI.getFileManager();
827827
auto Buffer = FileMgr.getBufferForFile(getCurrentFile());
828828
StringRef Magic = (*Buffer)->getMemBufferRef().getBuffer();
829-
bool IsRaw = (Magic.size() >= 4 && Magic[0] == 'C' && Magic[1] == 'P' &&
830-
Magic[2] == 'C' && Magic[3] == 'H');
829+
bool IsRaw = Magic.starts_with("CPCH");
831830
Out << " Module format: " << (IsRaw ? "raw" : "obj") << "\n";
832831

833832
Preprocessor &PP = CI.getPreprocessor();

0 commit comments

Comments
 (0)