Skip to content

Commit 7b2923d

Browse files
committed
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.
1 parent 57d0793 commit 7b2923d

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

src/ImageSharp/Formats/Gif/GifDecoderCore.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,9 @@ private void ReadLogicalScreenDescriptorAndGlobalColorTable(BufferedReadStream s
765765

766766
private unsafe struct ScratchBuffer
767767
{
768-
private fixed byte scratch[16];
768+
private const int Size = 16;
769+
private fixed byte scratch[Size];
769770

770-
public Span<byte> Span => MemoryMarshal.CreateSpan(ref this.scratch[0], 16);
771+
public Span<byte> Span => MemoryMarshal.CreateSpan(ref this.scratch[0], Size);
771772
}
772773
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ internal class ArithmeticScanDecoder : IJpegScanDecoder
5353

5454
private ArithmeticDecodingTable[] acDecodingTables;
5555

56+
// Don't make this a ReadOnlySpan<byte>, as the values need to get updated.
5657
private readonly byte[] fixedBin = { 113, 0, 0, 0 };
5758

5859
private readonly CancellationToken cancellationToken;

src/ImageSharp/Formats/Png/PngEncoderCore.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,8 +1412,9 @@ private static PngBitDepth SuggestBitDepth<TPixel>()
14121412

14131413
private unsafe struct ScratchBuffer
14141414
{
1415-
private fixed byte scratch[16];
1415+
private const int Size = 16;
1416+
private fixed byte scratch[Size];
14161417

1417-
public Span<byte> Span => MemoryMarshal.CreateSpan(ref this.scratch[0], 16);
1418+
public Span<byte> Span => MemoryMarshal.CreateSpan(ref this.scratch[0], Size);
14181419
}
14191420
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,9 @@ protected void WriteVp8XHeader(Stream stream, ExifProfile? exifProfile, XmpProfi
260260

261261
private unsafe struct ScratchBuffer
262262
{
263-
private fixed byte scratch[4];
263+
private const int Size = 4;
264+
private fixed byte scratch[Size];
264265

265-
public Span<byte> Span => MemoryMarshal.CreateSpan(ref this.scratch[0], 4);
266+
public Span<byte> Span => MemoryMarshal.CreateSpan(ref this.scratch[0], Size);
266267
}
267268
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,8 +1834,9 @@ public void Dispose()
18341834
/// </summary>
18351835
private unsafe struct ScratchBuffer
18361836
{
1837-
private fixed int scratch[256];
1837+
private const int Size = 256;
1838+
private fixed int scratch[Size];
18381839

1839-
public Span<int> Span => MemoryMarshal.CreateSpan(ref this.scratch[0], 256);
1840+
public Span<int> Span => MemoryMarshal.CreateSpan(ref this.scratch[0], Size);
18401841
}
18411842
}

0 commit comments

Comments
 (0)