From 7c52a62aa559c9363f71ed245ad73166109f81b8 Mon Sep 17 00:00:00 2001 From: smdn Date: Sat, 5 Feb 2022 01:39:15 +0900 Subject: [PATCH] use Stream.ReadAsync(Memory) if available --- src/Smdn.Fundamental.Stream/Smdn.IO/StreamExtensions.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Smdn.Fundamental.Stream/Smdn.IO/StreamExtensions.cs b/src/Smdn.Fundamental.Stream/Smdn.IO/StreamExtensions.cs index 9ba99a492..68199c185 100644 --- a/src/Smdn.Fundamental.Stream/Smdn.IO/StreamExtensions.cs +++ b/src/Smdn.Fundamental.Stream/Smdn.IO/StreamExtensions.cs @@ -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;