Minimize buffer allocations in Stream.CopyTo for seekable streams (dotnet/coreclr...
authorJames Ko <jamesqko@gmail.com>
Mon, 18 Jul 2016 05:18:26 +0000 (01:18 -0400)
committerJan Kotas <jkotas@microsoft.com>
Mon, 18 Jul 2016 05:18:26 +0000 (22:18 -0700)
commitf410b121677c95beca4b291a17cafe0c0aec3daa
tree5f91dff7ca9ae2bfe30363dbd07d3ca44d96c12b
parent1657b463cb5b1850e430bed7eefac51421e508e1
Minimize buffer allocations in Stream.CopyTo for seekable streams (dotnet/coreclr#4540)

The current implementation of  Stream.CopyTo  allocates a giant, 81920-byte buffer if no  bufferSize  parameter is passed. This is incredibly wasteful if the stream we're copying from can seek, because then we can use the  Length  and  Position  properties to determine how many bytes are left and allocate a buffer of that size.

Commit migrated from https://github.com/dotnet/coreclr/commit/91eb03162ceef78beb33548cacd98105376a2a4c
src/coreclr/src/mscorlib/src/System/IO/Stream.cs