Browse Source

Use constant to specify the size of the buffer

It's only one value for the fixed buffer size and the creation of the span -- so less error prone once the value needs to be updated.
pull/2415/head
Günther Foidl 3 years ago
parent
commit
7b2923d7ef
  1. 5
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  2. 1
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs
  3. 5
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  4. 5
      src/ImageSharp/Formats/Webp/BitWriter/BitWriterBase.cs
  5. 5
      src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs

5
src/ImageSharp/Formats/Gif/GifDecoderCore.cs

@ -765,8 +765,9 @@ internal sealed class GifDecoderCore : IImageDecoderInternals
private unsafe struct ScratchBuffer
{
private fixed byte scratch[16];
private const int Size = 16;
private fixed byte scratch[Size];
public Span<byte> Span => MemoryMarshal.CreateSpan(ref this.scratch[0], 16);
public Span<byte> Span => MemoryMarshal.CreateSpan(ref this.scratch[0], Size);
}
}

1
src/ImageSharp/Formats/Jpeg/Components/Decoder/ArithmeticScanDecoder.cs

@ -53,6 +53,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder
private ArithmeticDecodingTable[] acDecodingTables;
// Don't make this a ReadOnlySpan<byte>, as the values need to get updated.
private readonly byte[] fixedBin = { 113, 0, 0, 0 };
private readonly CancellationToken cancellationToken;

5
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -1412,8 +1412,9 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable
private unsafe struct ScratchBuffer
{
private fixed byte scratch[16];
private const int Size = 16;
private fixed byte scratch[Size];
public Span<byte> Span => MemoryMarshal.CreateSpan(ref this.scratch[0], 16);
public Span<byte> Span => MemoryMarshal.CreateSpan(ref this.scratch[0], Size);
}
}

5
src/ImageSharp/Formats/Webp/BitWriter/BitWriterBase.cs

@ -260,8 +260,9 @@ internal abstract class BitWriterBase
private unsafe struct ScratchBuffer
{
private fixed byte scratch[4];
private const int Size = 4;
private fixed byte scratch[Size];
public Span<byte> Span => MemoryMarshal.CreateSpan(ref this.scratch[0], 4);
public Span<byte> Span => MemoryMarshal.CreateSpan(ref this.scratch[0], Size);
}
}

5
src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs

@ -1834,8 +1834,9 @@ internal class Vp8LEncoder : IDisposable
/// </summary>
private unsafe struct ScratchBuffer
{
private fixed int scratch[256];
private const int Size = 256;
private fixed int scratch[Size];
public Span<int> Span => MemoryMarshal.CreateSpan(ref this.scratch[0], 256);
public Span<int> Span => MemoryMarshal.CreateSpan(ref this.scratch[0], Size);
}
}

Loading…
Cancel
Save