Skip to content

Commit cbcfc85

Browse files
authored
Merge pull request #72323 from bnbarham/rename-startswith
Rename startswith to starts_with
2 parents 1119a6e + 9779c18 commit cbcfc85

File tree

113 files changed

+276
-276
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+276
-276
lines changed

include/swift/ABI/ObjectFile.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class SwiftObjectFileFormatMachO : public SwiftObjectFileFormat {
6060
}
6161

6262
bool sectionContainsReflectionData(llvm::StringRef sectionName) override {
63-
return sectionName.startswith("__swift5_") || sectionName == "__const";
63+
return sectionName.starts_with("__swift5_") || sectionName == "__const";
6464
}
6565
};
6666

@@ -79,7 +79,7 @@ class SwiftObjectFileFormatELF : public SwiftObjectFileFormat {
7979
}
8080

8181
bool sectionContainsReflectionData(llvm::StringRef sectionName) override {
82-
return sectionName.startswith("swift5_");
82+
return sectionName.starts_with("swift5_");
8383
}
8484
};
8585

@@ -98,7 +98,7 @@ class SwiftObjectFileFormatCOFF : public SwiftObjectFileFormat {
9898
}
9999

100100
bool sectionContainsReflectionData(llvm::StringRef sectionName) override {
101-
return sectionName.startswith(".sw5");
101+
return sectionName.starts_with(".sw5");
102102
}
103103
};
104104
} // namespace swift

include/swift/APIDigester/ModuleAnalyzerNodes.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ class SDKNodeDecl: public SDKNode {
382382
swift::ReferenceOwnership getReferenceOwnership() const {
383383
return swift::ReferenceOwnership(ReferenceOwnership);
384384
}
385-
bool isObjc() const { return Usr.startswith("c:"); }
385+
bool isObjc() const { return Usr.starts_with("c:"); }
386386
static bool classof(const SDKNode *N);
387387
DeclKind getDeclKind() const { return DKind; }
388388
void printFullyQualifiedName(llvm::raw_ostream &OS) const;

include/swift/AST/ASTPrinter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class ASTPrinter {
232232
void printKeyword(StringRef name,
233233
const PrintOptions &Opts,
234234
StringRef Suffix = "") {
235-
if (Opts.SkipUnderscoredKeywords && name.startswith("_"))
235+
if (Opts.SkipUnderscoredKeywords && name.starts_with("_"))
236236
return;
237237
assert(!name.empty() && "Tried to print empty keyword");
238238
callPrintNamePre(PrintNameContext::Keyword);

include/swift/AST/Identifier.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ class Identifier {
174174
}
175175

176176
bool hasDollarPrefix() const {
177-
return str().startswith("$") && !(getLength() == 1);
177+
return str().starts_with("$") && !(getLength() == 1);
178178
}
179179

180180
bool hasUnderscoredNaming() const {
181-
return str().startswith("_");
181+
return str().starts_with("_");
182182
}
183183

184184
const void *getAsOpaquePointer() const {

include/swift/AST/RawComment.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct SingleRawComment {
5757
}
5858

5959
bool isGyb() const {
60-
return RawText.startswith("// ###");
60+
return RawText.starts_with("// ###");
6161
}
6262
};
6363

include/swift/Basic/PathRemapper.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class PathRemapper {
5353
// compatibility with Clang (especially because we propagate the flag to
5454
// ClangImporter as well).
5555
for (const auto &Mapping : PathMappings)
56-
if (Path.startswith(Mapping.first))
56+
if (Path.starts_with(Mapping.first))
5757
return (Twine(Mapping.second) +
5858
Path.substr(Mapping.first.size())).str();
5959
return Path.str();

include/swift/Basic/PrimitiveParsing.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static inline unsigned measureNewline(StringRef S) {
3030
}
3131

3232
static inline bool startsWithNewline(StringRef S) {
33-
return S.startswith("\n") || S.startswith("\r\n");
33+
return S.starts_with("\n") || S.starts_with("\r\n");
3434
}
3535

3636
/// Breaks a given string to lines and trims leading whitespace from them.

include/swift/Demangling/Demangler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ class Demangler : public NodeFactory {
415415
std::function<SymbolicReferenceResolver_t> SymbolicReferenceResolver;
416416

417417
bool nextIf(StringRef str) {
418-
if (!Text.substr(Pos).startswith(str)) return false;
418+
if (!Text.substr(Pos).starts_with(str)) return false;
419419
Pos += str.size();
420420
return true;
421421
}

include/swift/Parse/Parser.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ class Parser {
766766

767767
/// Check whether the current token starts with a multi-line string delimiter.
768768
bool startsWithMultilineStringDelimiter(Token Tok) {
769-
return Tok.getText().ltrim('#').startswith("\"\"\"");
769+
return Tok.getText().ltrim('#').starts_with("\"\"\"");
770770
}
771771

772772
/// Returns true if token is an identifier with the given value.

include/swift/Remote/MetadataReader.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ class MetadataReader {
866866
StringRef NameStr(Name);
867867

868868
// If this is a Swift-defined protocol, demangle it.
869-
if (NameStr.startswith("_TtP")) {
869+
if (NameStr.starts_with("_TtP")) {
870870
auto Demangled = dem.demangleSymbol(NameStr);
871871
if (!Demangled)
872872
return resolver.failure();

include/swift/SIL/SILFunction.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ class SILFunction
976976
/// TODO: This needs a better name.
977977
bool hasSemanticsAttrThatStartsWith(StringRef S) {
978978
return count_if(getSemanticsAttrs(), [&S](const std::string &Attr) -> bool {
979-
return StringRef(Attr).startswith(S);
979+
return StringRef(Attr).starts_with(S);
980980
});
981981
}
982982

lib/APIDigester/ModuleAnalyzerNodes.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,8 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
648648
};
649649
static auto getAsBool = [&](llvm::yaml::Node *N) -> bool {
650650
auto txt = cast<llvm::yaml::ScalarNode>(N)->getRawValue();
651-
assert(txt.startswith("false") || txt.startswith("true"));
652-
return txt.startswith("true");
651+
assert(txt.starts_with("false") || txt.starts_with("true"));
652+
return txt.starts_with("true");
653653
};
654654
SDKNodeKind Kind;
655655
SDKNodeInitInfo Info(Ctx);

lib/AST/ASTDemangler.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ TypeDecl *swift::Demangle::getTypeDeclForMangling(ASTContext &ctx,
6565
TypeDecl *swift::Demangle::getTypeDeclForUSR(ASTContext &ctx,
6666
StringRef usr,
6767
GenericSignature genericSig) {
68-
if (!usr.startswith("s:"))
68+
if (!usr.starts_with("s:"))
6969
return nullptr;
7070

7171
std::string mangling(usr);
@@ -104,7 +104,7 @@ TypeDecl *ASTBuilder::createTypeDecl(NodePointer node) {
104104
Type
105105
ASTBuilder::createBuiltinType(StringRef builtinName,
106106
StringRef mangledName) {
107-
if (builtinName.startswith(BUILTIN_TYPE_NAME_PREFIX)) {
107+
if (builtinName.starts_with(BUILTIN_TYPE_NAME_PREFIX)) {
108108
SmallVector<ValueDecl *, 1> decls;
109109

110110
StringRef strippedName =

lib/AST/ASTPrinter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5827,7 +5827,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
58275827
bool isLLDBExpressionModule(ModuleDecl *M) {
58285828
if (!M)
58295829
return false;
5830-
return M->getRealName().str().startswith(LLDB_EXPRESSIONS_MODULE_NAME_PREFIX);
5830+
return M->getRealName().str().starts_with(LLDB_EXPRESSIONS_MODULE_NAME_PREFIX);
58315831
}
58325832

58335833
bool shouldPrintFullyQualified(TypeBase *T) {

lib/AST/AutoDiff.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ static void parseAutoDiffBuiltinCommonConfig(
386386
StringRef &operationName, unsigned &arity, bool &throws) {
387387
// Parse '_arity'.
388388
constexpr char arityPrefix[] = "_arity";
389-
if (operationName.startswith(arityPrefix)) {
389+
if (operationName.starts_with(arityPrefix)) {
390390
operationName = operationName.drop_front(sizeof(arityPrefix) - 1);
391391
auto arityStr = operationName.take_while(llvm::isDigit);
392392
operationName = operationName.drop_front(arityStr.size());
@@ -398,7 +398,7 @@ static void parseAutoDiffBuiltinCommonConfig(
398398
}
399399
// Parse '_throws'.
400400
constexpr char throwsPrefix[] = "_throws";
401-
if (operationName.startswith(throwsPrefix)) {
401+
if (operationName.starts_with(throwsPrefix)) {
402402
operationName = operationName.drop_front(sizeof(throwsPrefix) - 1);
403403
throws = true;
404404
} else {
@@ -410,15 +410,15 @@ bool autodiff::getBuiltinApplyDerivativeConfig(
410410
StringRef operationName, AutoDiffDerivativeFunctionKind &kind,
411411
unsigned &arity, bool &throws) {
412412
constexpr char prefix[] = "applyDerivative";
413-
if (!operationName.startswith(prefix))
413+
if (!operationName.starts_with(prefix))
414414
return false;
415415
operationName = operationName.drop_front(sizeof(prefix) - 1);
416416
// Parse 'jvp' or 'vjp'.
417417
constexpr char jvpPrefix[] = "_jvp";
418418
constexpr char vjpPrefix[] = "_vjp";
419-
if (operationName.startswith(jvpPrefix))
419+
if (operationName.starts_with(jvpPrefix))
420420
kind = AutoDiffDerivativeFunctionKind::JVP;
421-
else if (operationName.startswith(vjpPrefix))
421+
else if (operationName.starts_with(vjpPrefix))
422422
kind = AutoDiffDerivativeFunctionKind::VJP;
423423
operationName = operationName.drop_front(sizeof(jvpPrefix) - 1);
424424
parseAutoDiffBuiltinCommonConfig(operationName, arity, throws);
@@ -428,7 +428,7 @@ bool autodiff::getBuiltinApplyDerivativeConfig(
428428
bool autodiff::getBuiltinApplyTransposeConfig(
429429
StringRef operationName, unsigned &arity, bool &throws) {
430430
constexpr char prefix[] = "applyTranspose";
431-
if (!operationName.startswith(prefix))
431+
if (!operationName.starts_with(prefix))
432432
return false;
433433
operationName = operationName.drop_front(sizeof(prefix) - 1);
434434
parseAutoDiffBuiltinCommonConfig(operationName, arity, throws);
@@ -439,9 +439,9 @@ bool autodiff::getBuiltinDifferentiableOrLinearFunctionConfig(
439439
StringRef operationName, unsigned &arity, bool &throws) {
440440
constexpr char differentiablePrefix[] = "differentiableFunction";
441441
constexpr char linearPrefix[] = "linearFunction";
442-
if (operationName.startswith(differentiablePrefix))
442+
if (operationName.starts_with(differentiablePrefix))
443443
operationName = operationName.drop_front(sizeof(differentiablePrefix) - 1);
444-
else if (operationName.startswith(linearPrefix))
444+
else if (operationName.starts_with(linearPrefix))
445445
operationName = operationName.drop_front(sizeof(linearPrefix) - 1);
446446
else
447447
return false;

lib/AST/Builtins.cpp

+19-19
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ IntrinsicInfo::getOrCreateAttributes(ASTContext &Ctx) const {
5959
Type swift::getBuiltinType(ASTContext &Context, StringRef Name) {
6060
// Vectors are VecNxT, where "N" is the number of elements and
6161
// T is the element type.
62-
if (Name.startswith("Vec")) {
62+
if (Name.starts_with("Vec")) {
6363
Name = Name.substr(3);
6464
StringRef::size_type xPos = Name.find('x');
6565
if (xPos == StringRef::npos)
@@ -2220,7 +2220,7 @@ llvm::Intrinsic::ID swift::getLLVMIntrinsicID(StringRef InName) {
22202220
using namespace llvm;
22212221

22222222
// Swift intrinsic names start with int_.
2223-
if (!InName.startswith("int_"))
2223+
if (!InName.starts_with("int_"))
22242224
return llvm::Intrinsic::not_intrinsic;
22252225
InName = InName.drop_front(strlen("int_"));
22262226

@@ -2533,15 +2533,15 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
25332533
}
25342534

25352535
// If this starts with fence, we have special suffixes to handle.
2536-
if (OperationName.startswith("ifdef_")) {
2536+
if (OperationName.starts_with("ifdef_")) {
25372537
OperationName = OperationName.drop_front(strlen("ifdef_"));
25382538
if (!Types.empty()) return nullptr;
25392539
if (OperationName.empty()) return nullptr;
25402540
return getIfdefOperation(Context, Id);
25412541
}
25422542

25432543
// If this starts with fence, we have special suffixes to handle.
2544-
if (OperationName.startswith("fence_")) {
2544+
if (OperationName.starts_with("fence_")) {
25452545
OperationName = OperationName.drop_front(strlen("fence_"));
25462546

25472547
// Verify we have a single integer, floating point, or pointer type.
@@ -2554,7 +2554,7 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
25542554
OperationName = OperationName.substr(Underscore);
25552555

25562556
// Accept singlethread if present.
2557-
if (OperationName.startswith("_singlethread"))
2557+
if (OperationName.starts_with("_singlethread"))
25582558
OperationName = OperationName.drop_front(strlen("_singlethread"));
25592559
// Nothing else is allowed in the name.
25602560
if (!OperationName.empty())
@@ -2563,7 +2563,7 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
25632563
}
25642564

25652565
// If this starts with cmpxchg, we have special suffixes to handle.
2566-
if (OperationName.startswith("cmpxchg_")) {
2566+
if (OperationName.starts_with("cmpxchg_")) {
25672567
OperationName = OperationName.drop_front(strlen("cmpxchg_"));
25682568

25692569
// Verify we have a single integer, floating point, or pointer type.
@@ -2596,7 +2596,7 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
25962596
}
25972597

25982598
// If this starts with atomicrmw, we have special suffixes to handle.
2599-
if (OperationName.startswith("atomicrmw_")) {
2599+
if (OperationName.starts_with("atomicrmw_")) {
26002600
OperationName = OperationName.drop_front(strlen("atomicrmw_"));
26012601

26022602
// Verify we have a single integer or pointer type.
@@ -2622,9 +2622,9 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
26222622
OperationName = OperationName.substr(Underscore);
26232623

26242624
// Accept volatile and singlethread if present.
2625-
if (OperationName.startswith("_volatile"))
2625+
if (OperationName.starts_with("_volatile"))
26262626
OperationName = OperationName.drop_front(strlen("_volatile"));
2627-
if (OperationName.startswith("_singlethread"))
2627+
if (OperationName.starts_with("_singlethread"))
26282628
OperationName = OperationName.drop_front(strlen("_singlethread"));
26292629
// Nothing else is allowed in the name.
26302630
if (!OperationName.empty())
@@ -2634,7 +2634,7 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
26342634

26352635
// If this starts with atomicload or atomicstore, we have special suffixes to
26362636
// handle.
2637-
if (OperationName.startswith("atomicload_")) {
2637+
if (OperationName.starts_with("atomicload_")) {
26382638
OperationName = OperationName.drop_front(strlen("atomicload_"));
26392639

26402640
// Verify we have a single integer, floating point, or pointer type.
@@ -2651,16 +2651,16 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
26512651
OperationName = OperationName.substr(Underscore);
26522652

26532653
// Accept volatile and singlethread if present.
2654-
if (OperationName.startswith("_volatile"))
2654+
if (OperationName.starts_with("_volatile"))
26552655
OperationName = OperationName.drop_front(strlen("_volatile"));
2656-
if (OperationName.startswith("_singlethread"))
2656+
if (OperationName.starts_with("_singlethread"))
26572657
OperationName = OperationName.drop_front(strlen("_singlethread"));
26582658
// Nothing else is allowed in the name.
26592659
if (!OperationName.empty())
26602660
return nullptr;
26612661
return getAtomicLoadOperation(Context, Id, T);
26622662
}
2663-
if (OperationName.startswith("atomicstore_")) {
2663+
if (OperationName.starts_with("atomicstore_")) {
26642664
OperationName = OperationName.drop_front(strlen("atomicstore_"));
26652665

26662666
// Verify we have a single integer, floating point, or pointer type.
@@ -2677,24 +2677,24 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
26772677
OperationName = OperationName.substr(Underscore);
26782678

26792679
// Accept volatile and singlethread if present.
2680-
if (OperationName.startswith("_volatile"))
2680+
if (OperationName.starts_with("_volatile"))
26812681
OperationName = OperationName.drop_front(strlen("_volatile"));
2682-
if (OperationName.startswith("_singlethread"))
2682+
if (OperationName.starts_with("_singlethread"))
26832683
OperationName = OperationName.drop_front(strlen("_singlethread"));
26842684
// Nothing else is allowed in the name.
26852685
if (!OperationName.empty())
26862686
return nullptr;
26872687
return getAtomicStoreOperation(Context, Id, T);
26882688
}
2689-
if (OperationName.startswith("allocWithTailElems_")) {
2689+
if (OperationName.starts_with("allocWithTailElems_")) {
26902690
OperationName = OperationName.drop_front(strlen("allocWithTailElems_"));
26912691
int NumTailTypes = 0;
26922692
if (OperationName.getAsInteger(10, NumTailTypes))
26932693
return nullptr;
26942694

26952695
return getAllocWithTailElemsOperation(Context, Id, NumTailTypes);
26962696
}
2697-
if (OperationName.startswith("applyDerivative_")) {
2697+
if (OperationName.starts_with("applyDerivative_")) {
26982698
AutoDiffDerivativeFunctionKind kind;
26992699
unsigned arity;
27002700
bool throws;
@@ -2704,7 +2704,7 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
27042704
return getAutoDiffApplyDerivativeFunction(Context, Id, kind, arity,
27052705
throws, /*thrownType=*/Type());
27062706
}
2707-
if (OperationName.startswith("applyTranspose_")) {
2707+
if (OperationName.starts_with("applyTranspose_")) {
27082708
unsigned arity;
27092709
bool throws;
27102710
if (!autodiff::getBuiltinApplyTransposeConfig(
@@ -3317,7 +3317,7 @@ StringRef BuiltinType::getTypeName(SmallVectorImpl<char> &result,
33173317
llvm::raw_svector_ostream UnderlyingOS(UnderlyingStrVec);
33183318
t->getElementType().print(UnderlyingOS);
33193319
}
3320-
if (UnderlyingStrVec.startswith(BUILTIN_TYPE_NAME_PREFIX))
3320+
if (UnderlyingStrVec.str().starts_with(BUILTIN_TYPE_NAME_PREFIX))
33213321
UnderlyingStr = UnderlyingStrVec.substr(8);
33223322
else
33233323
UnderlyingStr = UnderlyingStrVec;

lib/AST/ClangTypeConverter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ clang::QualType ClangTypeConverter::visitStructType(StructType *type) {
269269

270270
// Map vector types to the corresponding C vectors.
271271
#define MAP_SIMD_TYPE(TYPE_NAME, _, BUILTIN_KIND) \
272-
if (name.startswith(#TYPE_NAME)) { \
272+
if (name.starts_with(#TYPE_NAME)) { \
273273
return getClangVectorType(ctx, clang::BuiltinType::BUILTIN_KIND, \
274274
clang::VectorType::GenericVector, \
275275
name.drop_front(sizeof(#TYPE_NAME)-1)); \

0 commit comments

Comments
 (0)