Skip to content

Commit cf68e1b

Browse files
[Driver, Frontend] Use StringRef::contains (NFC)
1 parent b492b0b commit cf68e1b

File tree

10 files changed

+19
-22
lines changed

10 files changed

+19
-22
lines changed

clang/lib/Driver/Distro.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ static Distro::DistroType DetectDistro(llvm::vfs::FileSystem &VFS) {
118118
return Distro::Fedora;
119119
if (Data.startswith("Red Hat Enterprise Linux") ||
120120
Data.startswith("CentOS") || Data.startswith("Scientific Linux")) {
121-
if (Data.find("release 7") != StringRef::npos)
121+
if (Data.contains("release 7"))
122122
return Distro::RHEL7;
123-
else if (Data.find("release 6") != StringRef::npos)
123+
else if (Data.contains("release 6"))
124124
return Distro::RHEL6;
125-
else if (Data.find("release 5") != StringRef::npos)
125+
else if (Data.contains("release 5"))
126126
return Distro::RHEL5;
127127
}
128128
return Distro::UnknownDistro;

clang/lib/Driver/Driver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,7 @@ static llvm::Triple computeTargetTriple(const Driver &D,
436436
// GNU/Hurd's triples should have been -hurd-gnu*, but were historically made
437437
// -gnu* only, and we can not change this, so we have to detect that case as
438438
// being the Hurd OS.
439-
if (TargetTriple.find("-unknown-gnu") != StringRef::npos ||
440-
TargetTriple.find("-pc-gnu") != StringRef::npos)
439+
if (TargetTriple.contains("-unknown-gnu") || TargetTriple.contains("-pc-gnu"))
441440
Target.setOSName("hurd");
442441

443442
// Handle Apple-specific options available here.

clang/lib/Driver/ToolChain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ std::string ToolChain::GetLinkerPath(bool *LinkerIsLLD,
583583
// for the linker flavor is brittle. In addition, prepending "ld." or "ld64."
584584
// to a relative path is surprising. This is more complex due to priorities
585585
// among -B, COMPILER_PATH and PATH. --ld-path= should be used instead.
586-
if (UseLinker.find('/') != StringRef::npos)
586+
if (UseLinker.contains('/'))
587587
getDriver().Diag(diag::warn_drv_fuse_ld_path);
588588

589589
if (llvm::sys::path::is_absolute(UseLinker)) {

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ static void addDebugPrefixMapArg(const Driver &D, const ArgList &Args, ArgString
644644
for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
645645
options::OPT_fdebug_prefix_map_EQ)) {
646646
StringRef Map = A->getValue();
647-
if (Map.find('=') == StringRef::npos)
647+
if (!Map.contains('='))
648648
D.Diag(diag::err_drv_invalid_argument_to_option)
649649
<< Map << A->getOption().getName();
650650
else
@@ -659,7 +659,7 @@ static void addMacroPrefixMapArg(const Driver &D, const ArgList &Args,
659659
for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
660660
options::OPT_fmacro_prefix_map_EQ)) {
661661
StringRef Map = A->getValue();
662-
if (Map.find('=') == StringRef::npos)
662+
if (!Map.contains('='))
663663
D.Diag(diag::err_drv_invalid_argument_to_option)
664664
<< Map << A->getOption().getName();
665665
else
@@ -674,7 +674,7 @@ static void addCoveragePrefixMapArg(const Driver &D, const ArgList &Args,
674674
for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
675675
options::OPT_fcoverage_prefix_map_EQ)) {
676676
StringRef Map = A->getValue();
677-
if (Map.find('=') == StringRef::npos)
677+
if (!Map.contains('='))
678678
D.Diag(diag::err_drv_invalid_argument_to_option)
679679
<< Map << A->getOption().getName();
680680
else

clang/lib/Driver/ToolChains/FreeBSD.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void freebsd::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
110110
for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
111111
options::OPT_fdebug_prefix_map_EQ)) {
112112
StringRef Map = A->getValue();
113-
if (Map.find('=') == StringRef::npos)
113+
if (!Map.contains('='))
114114
D.Diag(diag::err_drv_invalid_argument_to_option)
115115
<< Map << A->getOption().getName();
116116
else {

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C,
930930
for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
931931
options::OPT_fdebug_prefix_map_EQ)) {
932932
StringRef Map = A->getValue();
933-
if (Map.find('=') == StringRef::npos)
933+
if (!Map.contains('='))
934934
D.Diag(diag::err_drv_invalid_argument_to_option)
935935
<< Map << A->getOption().getName();
936936
else {

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
206206
ExtraOpts.push_back("max-page-size=4096");
207207
}
208208

209-
if (GCCInstallation.getParentLibPath().find("opt/rh/") != StringRef::npos)
209+
if (GCCInstallation.getParentLibPath().contains("opt/rh/"))
210210
// With devtoolset on RHEL, we want to add a bin directory that is relative
211211
// to the detected gcc install, because if we are using devtoolset gcc then
212212
// we want to use other tools from devtoolset (e.g. ld) instead of the

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
999999
diag::err_analyzer_config_no_value) << configVal;
10001000
break;
10011001
}
1002-
if (val.find('=') != StringRef::npos) {
1002+
if (val.contains('=')) {
10031003
Diags.Report(SourceLocation(),
10041004
diag::err_analyzer_config_multiple_values)
10051005
<< configVal;
@@ -2061,13 +2061,13 @@ static bool ParseDependencyOutputArgs(DependencyOutputOptions &Opts,
20612061
if (!Args.hasArg(OPT_fno_sanitize_ignorelist)) {
20622062
for (const auto *A : Args.filtered(OPT_fsanitize_ignorelist_EQ)) {
20632063
StringRef Val = A->getValue();
2064-
if (Val.find('=') == StringRef::npos)
2064+
if (!Val.contains('='))
20652065
Opts.ExtraDeps.emplace_back(std::string(Val), EDK_SanitizeIgnorelist);
20662066
}
20672067
if (Opts.IncludeSystemHeaders) {
20682068
for (const auto *A : Args.filtered(OPT_fsanitize_system_ignorelist_EQ)) {
20692069
StringRef Val = A->getValue();
2070-
if (Val.find('=') == StringRef::npos)
2070+
if (!Val.contains('='))
20712071
Opts.ExtraDeps.emplace_back(std::string(Val), EDK_SanitizeIgnorelist);
20722072
}
20732073
}
@@ -2084,7 +2084,7 @@ static bool ParseDependencyOutputArgs(DependencyOutputOptions &Opts,
20842084
// Only the -fmodule-file=<file> form.
20852085
for (const auto *A : Args.filtered(OPT_fmodule_file)) {
20862086
StringRef Val = A->getValue();
2087-
if (Val.find('=') == StringRef::npos)
2087+
if (!Val.contains('='))
20882088
Opts.ExtraDeps.emplace_back(std::string(Val), EDK_ModuleFile);
20892089
}
20902090

@@ -2728,7 +2728,7 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
27282728
// Only the -fmodule-file=<file> form.
27292729
for (const auto *A : Args.filtered(OPT_fmodule_file)) {
27302730
StringRef Val = A->getValue();
2731-
if (Val.find('=') == StringRef::npos)
2731+
if (!Val.contains('='))
27322732
Opts.ModuleFiles.push_back(std::string(Val));
27332733
}
27342734

@@ -3003,7 +3003,7 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
30033003
// Only the -fmodule-file=<name>=<file> form.
30043004
for (const auto *A : Args.filtered(OPT_fmodule_file)) {
30053005
StringRef Val = A->getValue();
3006-
if (Val.find('=') != StringRef::npos){
3006+
if (Val.contains('=')) {
30073007
auto Split = Val.split('=');
30083008
Opts.PrebuiltModuleFiles.insert(
30093009
{std::string(Split.first), std::string(Split.second)});

clang/lib/Frontend/LayoutOverrideSource.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) {
4343
StringRef LineStr(Line);
4444

4545
// Determine whether the following line will start a
46-
if (LineStr.find("*** Dumping AST Record Layout") != StringRef::npos) {
46+
if (LineStr.contains("*** Dumping AST Record Layout")) {
4747
// Flush the last type/layout, if there is one.
4848
if (!CurrentType.empty())
4949
Layouts[CurrentType] = CurrentLayout;

clang/lib/Frontend/VerifyDiagnosticConsumer.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ class StandardDirective : public Directive {
9999
return true;
100100
}
101101

102-
bool match(StringRef S) override {
103-
return S.find(Text) != StringRef::npos;
104-
}
102+
bool match(StringRef S) override { return S.contains(Text); }
105103
};
106104

107105
/// RegexDirective - Directive with regular-expression matching.

0 commit comments

Comments
 (0)