Skip to content

Commit e924cf6

Browse files
committed
Replace usages of StringRef.find(Key) != StringRef::npos to StringRef.contains(Key)
1 parent 187f4db commit e924cf6

File tree

19 files changed

+31
-41
lines changed

19 files changed

+31
-41
lines changed

include/swift/IDE/APIDigesterData.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ struct CommonDiffItem: public APIDiffItem {
162162

163163
bool rightCommentUnderscored() const {
164164
DeclNameViewer Viewer(RightComment);
165-
auto HasUnderScore =
166-
[](StringRef S) { return S.find('_') != StringRef::npos; };
165+
auto HasUnderScore = [](StringRef S) { return S.contains('_'); };
167166
auto Args = Viewer.args();
168167
return HasUnderScore(Viewer.base()) ||
169168
std::any_of(Args.begin(), Args.end(), HasUnderScore);

lib/ClangImporter/ImportMacro.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static ValueDecl *importNumericLiteral(ClangImporter::Implementation &Impl,
8585
Impl.getClangPreprocessor().getSpelling(tok, SpellingBuffer, &Invalid);
8686
if (Invalid)
8787
return nullptr;
88-
if (TokSpelling.find('_') != StringRef::npos)
88+
if (TokSpelling.contains('_'))
8989
return nullptr;
9090
}
9191

lib/Driver/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static void validateCompilationConditionArgs(DiagnosticEngine &diags,
224224
const ArgList &args) {
225225
for (const Arg *A : args.filtered(options::OPT_D)) {
226226
StringRef name = A->getValue();
227-
if (name.find('=') != StringRef::npos) {
227+
if (name.contains('=')) {
228228
diags.diagnose(SourceLoc(),
229229
diag::cannot_assign_value_to_conditional_compilation_flag,
230230
name);

lib/Frontend/DiagnosticVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ findDiagnostic(std::vector<CapturedDiagnosticInfo> &CapturedDiagnostics,
128128

129129
// Verify the classification and string.
130130
if (I->Classification != Expected.Classification ||
131-
I->Message.find(Expected.MessageStr) == StringRef::npos)
131+
!I->Message.contains(Expected.MessageStr))
132132
continue;
133133

134134
// Okay, we found a match, hurray!

lib/Frontend/PrintingDiagnosticConsumer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ static void annotateSnippetWithInfo(SourceManager &SM,
911911
for (auto fixIt : Info.FixIts) {
912912
// Don't print multi-line fix-its inline, only include them at the end of
913913
// the message.
914-
if (fixIt.getText().find("\n") == std::string::npos)
914+
if (!fixIt.getText().contains("\n"))
915915
Snippet.addFixIt(fixIt.getRange(), fixIt.getText());
916916
}
917917
}

lib/IDE/SyntaxModel.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,8 +1620,7 @@ class DocFieldParser {
16201620

16211621
public:
16221622
DocFieldParser(StringRef text) : ptr(text.begin()), end(text.end()) {
1623-
assert(text.rtrim().find('\n') == StringRef::npos &&
1624-
"expected single line");
1623+
assert(!text.rtrim().contains('\n') && "expected single line");
16251624
}
16261625

16271626
// Case-insensitively match one of the following patterns:

lib/IDE/Utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,8 +921,8 @@ void ide::collectModuleNames(StringRef SDKPath,
921921
std::vector<std::string> &Modules) {
922922
std::string SDKName = getSDKName(SDKPath);
923923
std::string lowerSDKName = StringRef(SDKName).lower();
924-
bool isOSXSDK = StringRef(lowerSDKName).find("macosx") != StringRef::npos;
925-
bool isDeviceOnly = StringRef(lowerSDKName).find("iphoneos") != StringRef::npos;
924+
bool isOSXSDK = StringRef(lowerSDKName).contains("macosx");
925+
bool isDeviceOnly = StringRef(lowerSDKName).contains("iphoneos");
926926
auto Mods = isOSXSDK ? getOSXModuleList() : getiOSModuleList();
927927
Modules.insert(Modules.end(), Mods.begin(), Mods.end());
928928
if (isDeviceOnly) {

lib/IRGen/IRGenModule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ llvm::SmallString<32> getTargetDependentLibraryOption(const llvm::Triple &T,
11631163
llvm::SmallString<32> buffer;
11641164

11651165
if (T.isWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
1166-
bool quote = library.find(' ') != StringRef::npos;
1166+
bool quote = library.contains(' ');
11671167

11681168
buffer += "/DEFAULTLIB:";
11691169
if (quote)
@@ -1174,7 +1174,7 @@ llvm::SmallString<32> getTargetDependentLibraryOption(const llvm::Triple &T,
11741174
if (quote)
11751175
buffer += '"';
11761176
} else if (T.isPS4()) {
1177-
bool quote = library.find(' ') != StringRef::npos;
1177+
bool quote = library.contains(' ');
11781178

11791179
buffer += "\01";
11801180
if (quote)

lib/LLVMPasses/ARCEntryPointBuilder.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ class ARCEntryPointBuilder {
193193
// intrinsics are atomic today.
194194
if (I->getIntrinsicID() != llvm::Intrinsic::not_intrinsic)
195195
return false;
196-
return (I->getCalledFunction()->getName().find("nonatomic") !=
197-
llvm::StringRef::npos);
196+
return (I->getCalledFunction()->getName().contains("nonatomic"));
198197
}
199198

200199
bool isAtomic(CallInst *I) {

lib/SILOptimizer/IPO/GlobalOpt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ static void removeToken(SILValue Op) {
236236
if (!(GAI->use_empty() || GAI->hasOneUse()))
237237
return;
238238
// If it is not a *_token global variable, bail.
239-
if (!Global || Global->getName().find("_token") == StringRef::npos)
239+
if (!Global || !Global->getName().contains("_token"))
240240
return;
241241
GAI->getModule().eraseGlobalVariable(Global);
242242
GAI->replaceAllUsesWithUndef();

0 commit comments

Comments
 (0)