Skip to content

Commit caf1a55

Browse files
Merge pull request #35229 from mininny/switch-find-to-contains
[NFC] Replace uses of find(x) != end() idiom with contains(x) for StringRef and Set-like types
2 parents 7fe3187 + 53d1fc4 commit caf1a55

File tree

27 files changed

+50
-59
lines changed

27 files changed

+50
-59
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/AST/NameLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ class swift::MemberLookupTable {
10591059
/// Returns \c true if the lookup table has a complete accounting of the
10601060
/// given name.
10611061
bool isLazilyComplete(DeclBaseName name) const {
1062-
return LazilyCompleteNames.find(name) != LazilyCompleteNames.end();
1062+
return LazilyCompleteNames.contains(name);
10631063
}
10641064

10651065
/// Mark a given lazily-loaded name as being complete.

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: 2 additions & 2 deletions
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);
@@ -660,7 +660,7 @@ static SmallVector<StringRef, 8> findRemovedInputs(
660660
SmallVector<StringRef, 8> missingInputs;
661661
for (auto &previousInput : previousInputs) {
662662
auto previousInputArg = previousInput.getKey();
663-
if (inputArgs.find(previousInputArg) == inputArgs.end()) {
663+
if (!inputArgs.contains(previousInputArg)) {
664664
missingInputs.push_back(previousInputArg);
665665
}
666666
}

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/FrontendTool/TBD.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static bool validateSymbols(DiagnosticEngine &diags,
9393
irNotTBD.push_back(unmangledName);
9494
}
9595
} else {
96-
assert(symbolSet.find(name) == symbolSet.end() &&
96+
assert(!symbolSet.contains(name) &&
9797
"non-global value in value symbol table");
9898
}
9999
}

lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ getDeclsFromCrossImportOverlay(ModuleDecl *Overlay, ModuleDecl *Declaring,
424424
return false;
425425

426426
// Ignore an imports of modules also imported by the underlying module.
427-
if (PrevImported.find(Imported) != PrevImported.end())
427+
if (PrevImported.contains(Imported))
428428
return false;
429429
}
430430
if (auto *VD = dyn_cast<ValueDecl>(D)) {

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)

0 commit comments

Comments
 (0)