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

+1-2
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-2
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

+2-2
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

+2-2
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

+1-2
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

+1-1
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();

lib/SILOptimizer/PassManager/PassManager.cpp

+8-14
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,11 @@ static bool doPrintBefore(SILTransform *T, SILFunction *F) {
163163
return false;
164164

165165
if (!SILPrintOnlyFuns.empty() && F &&
166-
F->getName().find(SILPrintOnlyFuns, 0) == StringRef::npos)
166+
!F->getName().contains(SILPrintOnlyFuns))
167167
return false;
168168

169169
auto MatchFun = [&](const std::string &Str) -> bool {
170-
return T->getTag().find(Str) != StringRef::npos
171-
|| T->getID().find(Str) != StringRef::npos;
170+
return T->getTag().contains(Str) || T->getID().contains(Str);
172171
};
173172

174173
if (SILPrintBefore.end() !=
@@ -188,12 +187,11 @@ static bool doPrintAfter(SILTransform *T, SILFunction *F, bool Default) {
188187
return false;
189188

190189
if (!SILPrintOnlyFuns.empty() && F &&
191-
F->getName().find(SILPrintOnlyFuns, 0) == StringRef::npos)
190+
!F->getName().contains(SILPrintOnlyFuns))
192191
return false;
193192

194193
auto MatchFun = [&](const std::string &Str) -> bool {
195-
return T->getTag().find(Str) != StringRef::npos
196-
|| T->getID().find(Str) != StringRef::npos;
194+
return T->getTag().contains(Str) || T->getID().contains(Str);
197195
};
198196

199197
if (SILPrintAfter.end() !=
@@ -215,8 +213,7 @@ static bool isDisabled(SILTransform *T, SILFunction *F = nullptr) {
215213
return false;
216214

217215
for (const std::string &NamePattern : SILDisablePass) {
218-
if (T->getTag().find(NamePattern) != StringRef::npos
219-
|| T->getID().find(NamePattern) != StringRef::npos) {
216+
if (T->getTag().contains(NamePattern) || T->getID().contains(NamePattern)) {
220217
return true;
221218
}
222219
}
@@ -233,8 +230,7 @@ static void printModule(SILModule *Mod, bool EmitVerboseSIL) {
233230
std::find(SILPrintOnlyFun.begin(), SILPrintOnlyFun.end(), F.getName()))
234231
F.dump(EmitVerboseSIL);
235232

236-
if (!SILPrintOnlyFuns.empty() &&
237-
F.getName().find(SILPrintOnlyFuns, 0) != StringRef::npos)
233+
if (!SILPrintOnlyFuns.empty() && F.getName().contains(SILPrintOnlyFuns))
238234
F.dump(EmitVerboseSIL);
239235
}
240236
}
@@ -429,8 +425,7 @@ void SILPassManager::runPassOnFunction(unsigned TransIdx, SILFunction *F) {
429425
CurrentPassHasInvalidated = false;
430426

431427
auto MatchFun = [&](const std::string &Str) -> bool {
432-
return SFT->getTag().find(Str) != StringRef::npos ||
433-
SFT->getID().find(Str) != StringRef::npos;
428+
return SFT->getTag().contains(Str) || SFT->getID().contains(Str);
434429
};
435430
if ((SILVerifyBeforePass.end() != std::find_if(SILVerifyBeforePass.begin(),
436431
SILVerifyBeforePass.end(),
@@ -597,8 +592,7 @@ void SILPassManager::runModulePass(unsigned TransIdx) {
597592
}
598593

599594
auto MatchFun = [&](const std::string &Str) -> bool {
600-
return SMT->getTag().find(Str) != StringRef::npos ||
601-
SMT->getID().find(Str) != StringRef::npos;
595+
return SMT->getTag().contains(Str) || SMT->getID().contains(Str);
602596
};
603597
if ((SILVerifyBeforePass.end() != std::find_if(SILVerifyBeforePass.begin(),
604598
SILVerifyBeforePass.end(),

lib/SILOptimizer/Transforms/Outliner.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ class Outliner : public SILFunctionTransform {
12901290

12911291
// Dump function if requested.
12921292
if (DumpFuncsBeforeOutliner.size() &&
1293-
Fun->getName().find(DumpFuncsBeforeOutliner, 0) != StringRef::npos) {
1293+
Fun->getName().contains(DumpFuncsBeforeOutliner)) {
12941294
Fun->dump();
12951295
}
12961296

lib/SILOptimizer/UtilityPasses/CFGPrinter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class SILCFGPrinter : public SILFunctionTransform {
5353
if (!SILViewCFGOnlyFun.empty() && F && F->getName() != SILViewCFGOnlyFun)
5454
return;
5555
if (!SILViewCFGOnlyFuns.empty() && F &&
56-
F->getName().find(SILViewCFGOnlyFuns, 0) == StringRef::npos)
56+
!F->getName().contains(SILViewCFGOnlyFuns))
5757
return;
5858

5959
F->viewCFG();

lib/SILOptimizer/UtilityPasses/LoopRegionPrinter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class LoopRegionViewText : public SILModuleTransform {
5050
if (!SILViewCFGOnlyFun.empty() && fn.getName() != SILViewCFGOnlyFun)
5151
continue;
5252
if (!SILViewCFGOnlyFuns.empty() &&
53-
fn.getName().find(SILViewCFGOnlyFuns, 0) == StringRef::npos)
53+
!fn.getName().contains(SILViewCFGOnlyFuns))
5454
continue;
5555

5656
// Ok, we are going to analyze this function. Invalidate all state
@@ -74,7 +74,7 @@ class LoopRegionViewCFG : public SILModuleTransform {
7474
if (!SILViewCFGOnlyFun.empty() && fn.getName() != SILViewCFGOnlyFun)
7575
continue;
7676
if (!SILViewCFGOnlyFuns.empty() &&
77-
fn.getName().find(SILViewCFGOnlyFuns, 0) == StringRef::npos)
77+
!fn.getName().contains(SILViewCFGOnlyFuns))
7878
continue;
7979

8080
// Ok, we are going to analyze this function. Invalidate all state

lib/SILOptimizer/Utils/PerformanceInlinerUtils.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,8 @@ SILFunction *swift::getEligibleFunction(FullApplySite AI,
790790
return nullptr;
791791
}
792792

793-
if (!SILInlineNeverFuns.empty()
794-
&& Callee->getName().find(SILInlineNeverFuns, 0) != StringRef::npos)
793+
if (!SILInlineNeverFuns.empty() &&
794+
Callee->getName().contains(SILInlineNeverFuns))
795795
return nullptr;
796796

797797
if (!SILInlineNeverFun.empty() &&

tools/SourceKit/lib/Support/UIDRegistry.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void UIdent::print(llvm::raw_ostream &OS) const {
8585

8686
void *UIDRegistryImpl::get(StringRef Str) {
8787
assert(!Str.empty());
88-
assert(Str.find(' ') == StringRef::npos);
88+
assert(!Str.contains(' '));
8989
EntryTy *Ptr = 0;
9090
Queue.dispatchSync([&]{
9191
HashTableTy::iterator It = HashTable.find(Str);

tools/SourceKit/tools/sourcekitd/lib/API/sourcekitdAPI-Common.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ sourcekitd_object_t YAMLRequestParser::createObjFromNode(
721721
if (!Raw.getAsInteger(10, val))
722722
return sourcekitd_request_int64_create(val);
723723

724-
if (Raw.find(' ') != StringRef::npos)
724+
if (Raw.contains(' '))
725725
return withError("Found space in non-string value", Value, Error);
726726

727727
return sourcekitd_request_uid_create(

tools/driver/driver.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ static bool shouldRunAsSubcommand(StringRef ExecName,
104104
// Otherwise, we have a program argument. If it looks like an option or a
105105
// path, then invoke in interactive mode with the arguments as given.
106106
StringRef FirstArg(Args[1]);
107-
if (FirstArg.startswith("-") || FirstArg.find('.') != StringRef::npos ||
108-
FirstArg.find('/') != StringRef::npos)
107+
if (FirstArg.startswith("-") || FirstArg.contains('.') ||
108+
FirstArg.contains('/'))
109109
return false;
110110

111111
// Otherwise, we should have some sort of subcommand. Get the subcommand name

tools/swift-api-digester/ModuleAnalyzerNodes.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -2291,8 +2291,7 @@ int swift::ide::api::findDeclUsr(StringRef dumpPath, CheckerOptions Opts) {
22912291
FinderByLocation(StringRef Location): Location(Location) {}
22922292
void visit(SDKNode* Node) override {
22932293
if (auto *D = dyn_cast<SDKNodeDecl>(Node)) {
2294-
if (D->getLocation().find(Location) != StringRef::npos &&
2295-
!D->getUsr().empty()) {
2294+
if (D->getLocation().contains(Location) && !D->getUsr().empty()) {
22962295
llvm::outs() << D->getFullyQualifiedName() << ": " << D->getUsr() << "\n";
22972296
}
22982297
}

0 commit comments

Comments
 (0)