Remove StreamHelpers.ArrayPoolCopy.cs
authorStephen Toub <stoub@microsoft.com>
Mon, 31 Oct 2016 11:05:13 +0000 (07:05 -0400)
committerStephen Toub <stoub@microsoft.com>
Mon, 31 Oct 2016 11:05:13 +0000 (07:05 -0400)
It's no longer necessary now that Stream.CopyToAsync itself uses ArrayPool.

Commit migrated from https://github.com/dotnet/coreclr/commit/669ce2cff1bc0b19d6ac8e94ea1c5add5e4b797a

src/coreclr/src/mscorlib/corefx/System/IO/FileStream.Unix.cs
src/coreclr/src/mscorlib/corefx/System/IO/FileStream.Win32.cs
src/coreclr/src/mscorlib/corefx/System/IO/StreamHelpers.ArrayPoolCopy.cs [deleted file]
src/coreclr/src/mscorlib/model.xml
src/coreclr/src/mscorlib/mscorlib.shared.sources.props

index 3719670..aad3b46 100644 (file)
@@ -814,18 +814,6 @@ namespace System.IO
             throw new PlatformNotSupportedException();
         }
 
-        /// <summary>
-        /// Asynchronously reads the bytes from the current stream and writes them to another
-        /// stream, using a specified buffer size.
-        /// </summary>
-        /// <param name="destination">The stream to which the contents of the current stream will be copied.</param>
-        /// <param name="bufferSize">The size, in bytes, of the buffer.</param>
-        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
-        public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
-        {
-            return StreamHelpers.ArrayPoolCopyToAsync(this, destination, bufferSize, cancellationToken);
-        }
-
         /// <summary>Sets the current position of this stream to the given value.</summary>
         /// <param name="offset">The point relative to origin from which to begin seeking. </param>
         /// <param name="origin">
index f4c3384..8b9adb5 100644 (file)
@@ -1382,7 +1382,7 @@ namespace System.IO
             // case our custom CopyToAsync implementation isn't necessarily correct.
             if (!_useAsyncIO || GetType() != typeof(FileStream))
             {
-                return StreamHelpers.ArrayPoolCopyToAsync(this, destination, bufferSize, cancellationToken);
+                return base.CopyToAsync(destination, bufferSize, cancellationToken);
             }
 
             StreamHelpers.ValidateCopyToArgs(this, destination, bufferSize);
diff --git a/src/coreclr/src/mscorlib/corefx/System/IO/StreamHelpers.ArrayPoolCopy.cs b/src/coreclr/src/mscorlib/corefx/System/IO/StreamHelpers.ArrayPoolCopy.cs
deleted file mode 100644 (file)
index e56de31..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Buffers;
-using System.Diagnostics;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace System.IO
-{
-    /// <summary>Provides methods to help in the implementation of Stream-derived types.</summary>
-    internal static partial class StreamHelpers
-    {
-        /// <summary>
-        /// Provides an implementation usable as an override of Stream.CopyToAsync but that uses the shared
-        /// ArrayPool for the intermediate buffer rather than allocating a new buffer each time.
-        /// </summary>
-        /// <param name="source">The source stream from which to read.</param>
-        /// <param name="destination">The destination stream to which to write.</param>
-        /// <param name="bufferSize">The buffer size to use.</param>
-        /// <param name="cancellationToken">The cancellation token to use to cancel the operation.</param>
-        /// <remarks>
-        /// If/when the base CopyToAsync implementation is changed to use a pooled buffer, 
-        /// this will no longer be necessary.
-        /// </remarks>
-        public static Task ArrayPoolCopyToAsync(Stream source, Stream destination, int bufferSize, CancellationToken cancellationToken)
-        {
-            Debug.Assert(source != null);
-            ValidateCopyToArgs(source, destination, bufferSize);
-            return ArrayPoolCopyToAsyncCore(source, destination, bufferSize, cancellationToken);
-        }
-
-        /// <summary>Standard read/write loop using ReadAsync on the source and WriteAsync on the destination.</summary>
-        private static async Task ArrayPoolCopyToAsyncCore(Stream source, Stream destination, int bufferSize, CancellationToken cancellationToken)
-        {
-            byte[] buffer = ArrayPool<byte>.Shared.Rent(bufferSize);
-            bufferSize = 0; // reuse same field for high water mark to avoid needing another field in the state machine
-            try
-            {
-                while (true)
-                {
-                    int bytesRead = await source.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false);
-                    if (bytesRead == 0)
-                    {
-                        break;
-                    }
-                    if (bytesRead > bufferSize)
-                    {
-                        bufferSize = bytesRead;
-                    }
-                    await destination.WriteAsync(buffer, 0, bytesRead, cancellationToken).ConfigureAwait(false);
-                }
-            }
-            finally
-            {
-                Array.Clear(buffer, 0, bufferSize); // clear only the most we used
-                ArrayPool<byte>.Shared.Return(buffer, clearArray: false);
-            }
-        }
-    }
-}
index e14e23c..466b7cc 100644 (file)
       <Member Name="#ctor(System.String,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,System.Int32,System.IO.FileOptions)" />
       <Member Name="BeginRead(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)" />
       <Member Name="BeginWrite(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)" />
-      <Member Name="CopyToAsync(System.IO.Stream,System.Int32,System.Threading.CancellationToken)" />
       <Member Name="Dispose(System.Boolean)" />
       <Member Name="EndRead(System.IAsyncResult)" />
       <Member Name="EndWrite(System.IAsyncResult)" />
index c56075a..ba2a46e 100644 (file)
     <FileStreamSources Include="$(CoreFxSourcesRoot)\System\IO\FileStream.cs" />
     <FileStreamSources Include="$(CoreFxSourcesRoot)\System\IO\FileStream.NetStandard17.cs" />
     <FileStreamSources Include="$(CoreFxSourcesRoot)\System\IO\Error.cs" />
-    <FileStreamSources Include="$(CoreFxSourcesRoot)\System\IO\StreamHelpers.ArrayPoolCopy.cs" />
   </ItemGroup>
   <ItemGroup Condition="'$(FeatureCoreFxFileStream)' == 'true' and '$(TargetsUnix)' == 'true'">
     <SafehandleSources Include="$(CoreFxSourcesRoot)\Microsoft\Win32\SafeHandles\SafeFileHandle.Unix.cs" />