@@ -1972,12 +1972,6 @@ static void verifyAttrSerializable(const KIND ## Decl *D) {\
1972
1972
static void verifyAttrSerializable (const Decl *D) {}
1973
1973
#endif
1974
1974
1975
- static inline unsigned getOptionalOrZero (const llvm::Optional<unsigned > &X) {
1976
- if (X.hasValue ())
1977
- return X.getValue ();
1978
- return 0 ;
1979
- }
1980
-
1981
1975
bool Serializer::isDeclXRef (const Decl *D) const {
1982
1976
const DeclContext *topLevel = D->getDeclContext ()->getModuleScopeContext ();
1983
1977
if (topLevel->getParentModule () != M)
@@ -2382,8 +2376,8 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
2382
2376
if (X##_Val.hasValue ()) {\
2383
2377
const auto &Y = X##_Val.getValue ();\
2384
2378
X##_Major = Y.getMajor ();\
2385
- X##_Minor = getOptionalOrZero ( Y.getMinor ());\
2386
- X##_Subminor = getOptionalOrZero ( Y.getSubminor ());\
2379
+ X##_Minor = Y.getMinor (). getValueOr ( 0 );\
2380
+ X##_Subminor = Y.getSubminor (). getValueOr ( 0 );\
2387
2381
X##_HasMinor = Y.getMinor ().hasValue ();\
2388
2382
X##_HasSubminor = Y.getSubminor ().hasValue ();\
2389
2383
}
@@ -2894,8 +2888,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
2894
2888
2895
2889
// Reverse the list, and write the parameter lists, from outermost
2896
2890
// to innermost.
2897
- std::reverse (allGenericParams.begin (), allGenericParams.end ());
2898
- for (auto *genericParams : allGenericParams)
2891
+ for (auto *genericParams : swift::reversed (allGenericParams))
2899
2892
writeGenericParams (genericParams);
2900
2893
2901
2894
writeMembers (id, extension->getMembers (), isClassExtension);
@@ -4994,7 +4987,7 @@ void swift::serializeToBuffers(
4994
4987
std::unique_ptr<llvm::MemoryBuffer> *moduleDocBuffer,
4995
4988
const SILModule *M) {
4996
4989
4997
- assert (options.OutputPath && options. OutputPath [ 0 ] != ' \0 ' );
4990
+ assert (! StringRef::withNullAsEmpty ( options.OutputPath ). empty () );
4998
4991
{
4999
4992
SharedTimer timer (" Serialization, swiftmodule, to buffer" );
5000
4993
llvm::SmallString<1024 > buf;
@@ -5013,7 +5006,7 @@ void swift::serializeToBuffers(
5013
5006
std::move (buf), options.OutputPath );
5014
5007
}
5015
5008
5016
- if (options.DocOutputPath && options. DocOutputPath [ 0 ] != ' \0 ' ) {
5009
+ if (! StringRef::withNullAsEmpty ( options.DocOutputPath ). empty () ) {
5017
5010
SharedTimer timer (" Serialization, swiftdoc, to buffer" );
5018
5011
llvm::SmallString<1024 > buf;
5019
5012
llvm::raw_svector_ostream stream (buf);
@@ -5033,12 +5026,12 @@ void swift::serializeToBuffers(
5033
5026
void swift::serialize (ModuleOrSourceFile DC,
5034
5027
const SerializationOptions &options,
5035
5028
const SILModule *M) {
5036
- assert (options.OutputPath && options. OutputPath [ 0 ] != ' \0 ' );
5029
+ assert (! StringRef::withNullAsEmpty ( options.OutputPath ). empty () );
5037
5030
5038
- if (strcmp ( " - " , options.OutputPath ) == 0 ) {
5031
+ if (StringRef ( options.OutputPath ) == " - " ) {
5039
5032
// Special-case writing to stdout.
5040
5033
Serializer::writeToStream (llvm::outs (), DC, M, options);
5041
- assert (! options.DocOutputPath || options. DocOutputPath [ 0 ] == ' \0 ' );
5034
+ assert (StringRef::withNullAsEmpty ( options.DocOutputPath ). empty () );
5042
5035
return ;
5043
5036
}
5044
5037
@@ -5052,7 +5045,7 @@ void swift::serialize(ModuleOrSourceFile DC,
5052
5045
if (hadError)
5053
5046
return ;
5054
5047
5055
- if (options.DocOutputPath && options. DocOutputPath [ 0 ] != ' \0 ' ) {
5048
+ if (! StringRef::withNullAsEmpty ( options.DocOutputPath ). empty () ) {
5056
5049
(void )withOutputFile (getContext (DC).Diags ,
5057
5050
options.DocOutputPath ,
5058
5051
[&](raw_ostream &out) {
0 commit comments