Skip to content

Commit 1e58db2

Browse files
Remove ChunkedMemoryStream
1 parent e69a507 commit 1e58db2

File tree

9 files changed

+36
-983
lines changed

9 files changed

+36
-983
lines changed

src/ImageSharp/Formats/Gif/GifDecoderCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ private void ReadApplicationExtension(BufferedReadStream stream)
317317
bool isXmp = this.buffer.Span.StartsWith(GifConstants.XmpApplicationIdentificationBytes);
318318
if (isXmp && !this.skipMetadata)
319319
{
320-
GifXmpApplicationExtension extension = GifXmpApplicationExtension.Read(stream, this.memoryAllocator);
320+
GifXmpApplicationExtension extension = GifXmpApplicationExtension.Read(stream);
321321
if (extension.Data.Length > 0)
322322
{
323323
this.metadata!.XmpProfile = new XmpProfile(extension.Data);

src/ImageSharp/Formats/Gif/Sections/GifXmpApplicationExtension.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4-
using SixLabors.ImageSharp.IO;
54
using SixLabors.ImageSharp.Memory;
65

76
namespace SixLabors.ImageSharp.Formats.Gif;
@@ -26,11 +25,10 @@ namespace SixLabors.ImageSharp.Formats.Gif;
2625
/// Reads the XMP metadata from the specified stream.
2726
/// </summary>
2827
/// <param name="stream">The stream to read from.</param>
29-
/// <param name="allocator">The memory allocator.</param>
3028
/// <returns>The XMP metadata</returns>
31-
public static GifXmpApplicationExtension Read(Stream stream, MemoryAllocator allocator)
29+
public static GifXmpApplicationExtension Read(Stream stream)
3230
{
33-
byte[] xmpBytes = ReadXmpData(stream, allocator);
31+
byte[] xmpBytes = ReadXmpData(stream);
3432

3533
// Exclude the "magic trailer", see XMP Specification Part 3, 1.1.2 GIF
3634
int xmpLength = xmpBytes.Length - 256; // 257 - unread 0x0
@@ -71,9 +69,9 @@ public int WriteTo(Span<byte> buffer)
7169
return this.ContentLength;
7270
}
7371

74-
private static byte[] ReadXmpData(Stream stream, MemoryAllocator allocator)
72+
private static byte[] ReadXmpData(Stream stream)
7573
{
76-
using ChunkedMemoryStream bytes = new(allocator);
74+
using MemoryStream bytes = new();
7775

7876
// XMP data doesn't have a fixed length nor is there an indicator of the length.
7977
// So we simply read one byte at a time until we hit the 0x0 value at the end

src/ImageSharp/Formats/ImageDecoder.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4-
using SixLabors.ImageSharp.IO;
54
using SixLabors.ImageSharp.PixelFormats;
65
using SixLabors.ImageSharp.Processing;
76

@@ -210,7 +209,7 @@ T PerformActionAndResetPosition(Stream s, long position)
210209
}
211210

212211
Configuration configuration = options.Configuration;
213-
using ChunkedMemoryStream memoryStream = new(configuration.MemoryAllocator);
212+
using MemoryStream memoryStream = new();
214213
stream.CopyTo(memoryStream, configuration.StreamProcessingBufferSize);
215214
memoryStream.Position = 0;
216215

@@ -266,11 +265,6 @@ Task<T> PerformActionAndResetPosition(Stream s, long position, CancellationToken
266265
return PerformActionAndResetPosition(ms, ms.Position, cancellationToken);
267266
}
268267

269-
if (stream is ChunkedMemoryStream cms)
270-
{
271-
return PerformActionAndResetPosition(cms, cms.Position, cancellationToken);
272-
}
273-
274268
return CopyToMemoryStreamAndActionAsync(options, stream, PerformActionAndResetPosition, cancellationToken);
275269
}
276270

@@ -282,9 +276,11 @@ private static async Task<T> CopyToMemoryStreamAndActionAsync<T>(
282276
{
283277
long position = stream.CanSeek ? stream.Position : 0;
284278
Configuration configuration = options.Configuration;
285-
await using ChunkedMemoryStream memoryStream = new(configuration.MemoryAllocator);
279+
280+
await using MemoryStream memoryStream = new();
286281
await stream.CopyToAsync(memoryStream, configuration.StreamProcessingBufferSize, cancellationToken).ConfigureAwait(false);
287282
memoryStream.Position = 0;
283+
288284
return await action(memoryStream, position, cancellationToken).ConfigureAwait(false);
289285
}
290286

src/ImageSharp/Formats/ImageEncoder.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4-
using SixLabors.ImageSharp.IO;
54
using SixLabors.ImageSharp.PixelFormats;
65

76
namespace SixLabors.ImageSharp.Formats;
@@ -48,8 +47,8 @@ private void EncodeWithSeekableStream<TPixel>(Image<TPixel> image, Stream stream
4847
}
4948
else
5049
{
51-
using ChunkedMemoryStream ms = new(configuration.MemoryAllocator);
52-
this.Encode(image, stream, cancellationToken);
50+
using MemoryStream ms = new();
51+
this.Encode(image, ms, cancellationToken);
5352
ms.Position = 0;
5453
ms.CopyTo(stream, configuration.StreamProcessingBufferSize);
5554
}
@@ -65,7 +64,7 @@ private async Task EncodeWithSeekableStreamAsync<TPixel>(Image<TPixel> image, St
6564
}
6665
else
6766
{
68-
using ChunkedMemoryStream ms = new(configuration.MemoryAllocator);
67+
await using MemoryStream ms = new();
6968
await DoEncodeAsync(ms);
7069
ms.Position = 0;
7170
await ms.CopyToAsync(stream, configuration.StreamProcessingBufferSize, cancellationToken)

0 commit comments

Comments
 (0)