Skip to content

Commit 344293d

Browse files
authored
Reduce bounds checks and branches
1 parent 84d4f98 commit 344293d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Http/WebUtilities/src/ReasonPhrases.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,13 @@ public static class ReasonPhrases
182182
/// <returns>The reason phrase, or <see cref="string.Empty"/> if the status code is unknown.</returns>
183183
public static string GetReasonPhrase(int statusCode)
184184
{
185-
if (statusCode >= 100 && statusCode < 600)
185+
if ((uint)(statusCode - 100) < 500)
186186
{
187-
int i = Math.DivRem(statusCode, 100, out int j);
188-
if (j < HttpReasonPhrases[i].Length)
187+
var (i, j) = Math.DivRem((uint)statusCode, 100);
188+
string[] phrases = HttpReasonPhrases[i];
189+
if (j < (uint)phrases.Length)
189190
{
190-
return HttpReasonPhrases[i][j];
191+
return phrases[j];
191192
}
192193
}
193194
return string.Empty;

0 commit comments

Comments
 (0)