Skip to content

Commit a0b79e7

Browse files
lechu445lechu445grbell-ms
authored
Override CopyTo to improve performance (#278)
* Override CopyTo to improve performance If CopyTo is not overriden, it is used the default implementation in Stream class which is inefficient as it uses ArrayPool and writes in loop. * Update src/RecyclableMemoryStream.cs good idea! Co-authored-by: Gregory Bell <65985703+grbell-ms@users.noreply.github.com> --------- Co-authored-by: lechu445 <xxx@example.com> Co-authored-by: Gregory Bell <65985703+grbell-ms@users.noreply.github.com>
1 parent 5397c3c commit a0b79e7

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/RecyclableMemoryStream.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,14 @@ public override byte[] GetBuffer()
551551
return this.largeBuffer;
552552
}
553553

554+
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1
555+
/// <inheritdoc/>
556+
public override void CopyTo(Stream destination, int bufferSize)
557+
{
558+
WriteTo(destination, this.position, this.length - this.position);
559+
}
560+
#endif
561+
554562
/// <summary>Asynchronously reads all the bytes from the current position in this stream and writes them to another stream.</summary>
555563
/// <param name="destination">The stream to which the contents of the current stream will be copied.</param>
556564
/// <param name="bufferSize">This parameter is ignored.</param>

0 commit comments

Comments
 (0)