summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazu Hirata <kazu@google.com>2024-01-31 23:54:09 -0800
committerKazu Hirata <kazu@google.com>2024-01-31 23:54:09 -0800
commitb67ce7e34948d4d954d3cfedb29ffc94861ca0b2 (patch)
tree9bea1b9f5b0648281fc44689b4ee2a0947127349
parent39fa304866e16f1408a0cab9437e47e4ebacf206 (diff)
[clang] Use StringRef::starts_with (NFC)
-rw-r--r--clang/lib/AST/TypePrinter.cpp2
-rw-r--r--clang/lib/Basic/Targets/X86.cpp2
-rw-r--r--clang/lib/CodeGen/CGObjCMac.cpp6
-rw-r--r--clang/lib/Format/FormatTokenLexer.cpp2
-rw-r--r--clang/lib/Frontend/FrontendActions.cpp3
5 files changed, 6 insertions, 9 deletions
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 63e56a8296db..436328075771 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2264,7 +2264,7 @@ printTo(raw_ostream &OS, ArrayRef<TA> Args, const PrintingPolicy &Policy,
// If this is the first argument and its string representation
// begins with the global scope specifier ('::foo'), add a space
// to avoid printing the diagraph '<:'.
- if (FirstArg && !ArgString.empty() && ArgString[0] == ':')
+ if (FirstArg && ArgString.starts_with(":"))
OS << ' ';
OS << ArgString;
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index a68b662d9401..c6fc17fcc1b7 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -151,7 +151,7 @@ bool X86TargetInfo::initFeatureMap(
// Postpone AVX10 features handling after AVX512 settled.
UpdatedAVX10FeaturesVec.push_back(Feature);
continue;
- } else if (!HasAVX512F && Feature.substr(0, 7) == "+avx512") {
+ } else if (!HasAVX512F && StringRef(Feature).starts_with("+avx512")) {
HasAVX512F = true;
LastAVX512 = Feature;
} else if (HasAVX512F && Feature == "-avx512f") {
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 517f7cddebc1..27d77e9a8a55 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -5038,12 +5038,10 @@ std::string CGObjCCommonMac::GetSectionName(StringRef Section,
return ("__DATA," + Section + "," + MachOAttributes).str();
}
case llvm::Triple::ELF:
- assert(Section.substr(0, 2) == "__" &&
- "expected the name to begin with __");
+ assert(Section.starts_with("__") && "expected the name to begin with __");
return Section.substr(2).str();
case llvm::Triple::COFF:
- assert(Section.substr(0, 2) == "__" &&
- "expected the name to begin with __");
+ assert(Section.starts_with("__") && "expected the name to begin with __");
return ("." + Section.substr(2) + "$B").str();
case llvm::Triple::Wasm:
case llvm::Triple::GOFF:
diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp
index d7de09ef0e12..a87d0ba3dbbf 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -1420,7 +1420,7 @@ void FormatTokenLexer::readRawToken(FormatToken &Tok) {
// For formatting, treat unterminated string literals like normal string
// literals.
if (Tok.is(tok::unknown)) {
- if (!Tok.TokenText.empty() && Tok.TokenText[0] == '"') {
+ if (Tok.TokenText.starts_with("\"")) {
Tok.Tok.setKind(tok::string_literal);
Tok.IsUnterminatedLiteral = true;
} else if (Style.isJavaScript() && Tok.TokenText == "''") {
diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp
index c1d6e7145536..b9ed5dedfa42 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -826,8 +826,7 @@ void DumpModuleInfoAction::ExecuteAction() {
auto &FileMgr = CI.getFileManager();
auto Buffer = FileMgr.getBufferForFile(getCurrentFile());
StringRef Magic = (*Buffer)->getMemBufferRef().getBuffer();
- bool IsRaw = (Magic.size() >= 4 && Magic[0] == 'C' && Magic[1] == 'P' &&
- Magic[2] == 'C' && Magic[3] == 'H');
+ bool IsRaw = Magic.starts_with("CPCH");
Out << " Module format: " << (IsRaw ? "raw" : "obj") << "\n";
Preprocessor &PP = CI.getPreprocessor();