Skip to content

Commit

Permalink
use Stream.ReadAsync(Memory) if available
Browse files Browse the repository at this point in the history
  • Loading branch information
smdn committed Feb 4, 2022
1 parent 7895451 commit 7c52a62
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Smdn.Fundamental.Stream/Smdn.IO/StreamExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ async Task CopyToAsyncCore()
var buffer = new byte[bufferSize]; // TODO: array pool

for (; ; ) {
var read = await stream.ReadAsync(buffer, 0, bufferSize, cancellationToken).ConfigureAwait(false);
var read =
#if SYSTEM_IO_STREAM_READASYNC_MEMORY_OF_BYTE
await stream.ReadAsync(buffer.AsMemory(0, bufferSize), cancellationToken)
#else
await stream.ReadAsync(buffer, 0, bufferSize, cancellationToken)
#endif
.ConfigureAwait(false);

if (read <= 0)
break;
Expand Down

0 comments on commit 7c52a62

Please sign in to comment.