diff --git a/Schema/src/testing/SchemaMemoryStream.cs b/Schema/src/testing/SchemaMemoryStream.cs index 0e31d0a..a9600a4 100644 --- a/Schema/src/testing/SchemaMemoryStream.cs +++ b/Schema/src/testing/SchemaMemoryStream.cs @@ -50,7 +50,7 @@ public long Position { public void Write(ReadOnlySpan src) => impl.Write(src); public void Write(IReadableStream readableStream) - => impl.WriteImpl(readableStream); + => readableStream.CopyTo(impl); public Endianness Endianness => EndiannessUtil.SystemEndianness; } diff --git a/Schema/src/util/streams/BaseStreamImpls.cs b/Schema/src/util/streams/BaseStreamImpls.cs deleted file mode 100644 index fb1be13..0000000 --- a/Schema/src/util/streams/BaseStreamImpls.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.IO; -using System.Runtime.CompilerServices; - -using CommunityToolkit.HighPerformance; - -namespace schema.util.streams { - public static class BasicStreamImpls { - /// - /// (Straight-up copied from the implementation of Stream.CopyTo()) - /// We pick a value that is the largest multiple of 4096 that is still smaller than the large object heap threshold (85K). - /// The CopyTo/CopyToAsync buffer is short-lived and is likely to be collected at Gen0, and it offers a significant - /// improvement in Copy performance. - /// - private const int DEFAULT_COPY_BUFFER_SIZE = 81920; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static void WriteImpl(this Stream impl, - IReadableStream readableStream) { - if (readableStream is ReadableStream readableStreamImpl) { - readableStreamImpl.Impl.CopyTo(impl); - return; - } - - Span buffer = stackalloc byte[DEFAULT_COPY_BUFFER_SIZE]; - int bytesRead; - while ((bytesRead = readableStream.TryToReadIntoBuffer(buffer)) != 0) { - impl.Write(buffer.Slice(0, bytesRead)); - } - } - } -} \ No newline at end of file diff --git a/Schema/src/util/streams/WritableStream.cs b/Schema/src/util/streams/WritableStream.cs index 4494d51..7721dd1 100644 --- a/Schema/src/util/streams/WritableStream.cs +++ b/Schema/src/util/streams/WritableStream.cs @@ -6,14 +6,6 @@ namespace schema.util.streams { public class WritableStream(Stream impl) : ISeekableWritableStream { - /// - /// (Straight-up copied from the implementation of Stream.CopyTo()) - /// We pick a value that is the largest multiple of 4096 that is still smaller than the large object heap threshold (85K). - /// The CopyTo/CopyToAsync buffer is short-lived and is likely to be collected at Gen0, and it offers a significant - /// improvement in Copy performance. - /// - private const int DEFAULT_COPY_BUFFER_SIZE = 81920; - public static implicit operator WritableStream(Stream impl) => new(impl); internal Stream Impl => impl; @@ -39,6 +31,6 @@ public long Length { [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Write(IReadableStream readableStream) - => impl.WriteImpl(readableStream); + => readableStream.CopyTo(impl); } } \ No newline at end of file