Skip to content

Commit 8d9db2f

Browse files
Use ArgumentOutOfRangeException Throw methods in SendFileResponseExtensions..CheckRange (#56420)
* Use ArgumentOutOfRangeException Throw methods in SendFileResponseExtensions..CheckRange To allow inlining by the JIT. * fixed logic error * Update src/Http/Http.Extensions/src/SendFileResponseExtensions.cs Co-authored-by: Andrew Casey <amcasey@users.noreply.github.com> --------- Co-authored-by: Andrew Casey <amcasey@users.noreply.github.com>
1 parent 7b757a0 commit 8d9db2f

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/Http/Http.Extensions/src/SendFileResponseExtensions.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,12 @@ private static async Task SendFileAsyncCore(HttpResponse response, string fileNa
124124

125125
private static void CheckRange(long offset, long? count, long fileLength)
126126
{
127-
if (offset < 0 || offset > fileLength)
127+
ArgumentOutOfRangeException.ThrowIfLessThan(offset, 0);
128+
ArgumentOutOfRangeException.ThrowIfGreaterThan(offset, fileLength);
129+
if (count is {} countValue)
128130
{
129-
throw new ArgumentOutOfRangeException(nameof(offset), offset, string.Empty);
130-
}
131-
if (count.HasValue &&
132-
(count.GetValueOrDefault() < 0 || count.GetValueOrDefault() > fileLength - offset))
133-
{
134-
throw new ArgumentOutOfRangeException(nameof(count), count, string.Empty);
131+
ArgumentOutOfRangeException.ThrowIfLessThan(countValue, 0, nameof(count));
132+
ArgumentOutOfRangeException.ThrowIfGreaterThan(countValue, fileLength - offset, nameof(count));
135133
}
136134
}
137135
}

0 commit comments

Comments
 (0)