Skip to content

Commit 393f78f

Browse files
committed
Invert condition for early returns
1 parent 7400e9a commit 393f78f

File tree

1 file changed

+28
-30
lines changed
  • src/libraries/System.Private.Uri/src/System

1 file changed

+28
-30
lines changed

src/libraries/System.Private.Uri/src/System/UriExt.cs

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private void CreateThis(string? uri, bool dontEscape, UriKind uriKind, in UriCre
2121
{
2222
DebugAssertInCtor();
2323

24-
if ((int)uriKind < (int)UriKind.RelativeOrAbsolute || (int)uriKind > (int)UriKind.Relative)
24+
if (uriKind is < UriKind.RelativeOrAbsolute or > UriKind.Relative)
2525
{
2626
throw new ArgumentException(SR.Format(SR.net_uri_InvalidUriKind, uriKind));
2727
}
@@ -57,37 +57,11 @@ private void CreateThis(string? uri, bool dontEscape, UriKind uriKind, in UriCre
5757
_originalUnicodeString = _string; // original string location changed
5858
}
5959

60-
if (err == ParsingError.None)
61-
{
62-
if (IsImplicitFile)
63-
{
64-
if (uriKind == UriKind.Relative)
65-
{
66-
_syntax = null!; // make it be relative Uri
67-
_flags &= Flags.UserEscaped; // the only flag that makes sense for a relative uri
68-
return null;
69-
}
70-
71-
// V1 compat
72-
// A relative Uri wins over implicit UNC path unless the UNC path is of the form "\\something" and
73-
// uriKind != Absolute
74-
// A relative Uri wins over implicit Unix path unless uriKind == Absolute
75-
if (NotAny(Flags.DosPath) && uriKind == UriKind.RelativeOrAbsolute &&
76-
((_string.Length >= 2 && (_string[0] != '\\' || _string[1] != '\\'))
77-
|| (!OperatingSystem.IsWindows() && InFact(Flags.UnixPath))))
78-
{
79-
_syntax = null!; //make it be relative Uri
80-
_flags &= Flags.UserEscaped; // the only flag that makes sense for a relative uri
81-
return null;
82-
// Otherwise an absolute file Uri wins when it's of the form "\\something"
83-
}
84-
}
85-
}
86-
else
60+
if (err != ParsingError.None)
8761
{
8862
// If we encountered any parsing errors that indicate this may be a relative Uri,
8963
// and we'll allow relative Uri's, then create one.
90-
if (err <= ParsingError.LastErrorOkayForRelativeUris)
64+
if (uriKind != UriKind.Absolute && err <= ParsingError.LastErrorOkayForRelativeUris)
9165
{
9266
_flags &= Flags.UserEscaped | Flags.HasUnicode; // the only flags that makes sense for a relative uri
9367
if (hasUnicode)
@@ -105,7 +79,31 @@ private void CreateThis(string? uri, bool dontEscape, UriKind uriKind, in UriCre
10579
}
10680
}
10781

108-
Debug.Assert(err == ParsingError.None && _syntax is not null);
82+
Debug.Assert(_syntax is not null);
83+
84+
if (IsImplicitFile)
85+
{
86+
if (uriKind == UriKind.Relative)
87+
{
88+
_syntax = null!; // make it be relative Uri
89+
_flags &= Flags.UserEscaped; // the only flag that makes sense for a relative uri
90+
return null;
91+
}
92+
93+
// V1 compat
94+
// A relative Uri wins over implicit UNC path unless the UNC path is of the form "\\something" and
95+
// uriKind != Absolute
96+
// A relative Uri wins over implicit Unix path unless uriKind == Absolute
97+
if (NotAny(Flags.DosPath) && uriKind == UriKind.RelativeOrAbsolute &&
98+
((_string.Length >= 2 && (_string[0] != '\\' || _string[1] != '\\'))
99+
|| (!OperatingSystem.IsWindows() && InFact(Flags.UnixPath))))
100+
{
101+
_syntax = null!; //make it be relative Uri
102+
_flags &= Flags.UserEscaped; // the only flag that makes sense for a relative uri
103+
return null;
104+
// Otherwise an absolute file Uri wins when it's of the form "\\something"
105+
}
106+
}
109107

110108
if (_syntax.IsSimple)
111109
{

0 commit comments

Comments
 (0)