From 50c1aab54fef01b1e21da4cbb156a6a9da4a438c Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Tue, 31 May 2022 20:22:56 +0200 Subject: [PATCH] Use stackalloc --- .../Formats/Tiff/Compression/Decompressors/T4BitReader.cs | 1 + .../BlackIsZero24TiffColor{TPixel}.cs | 4 ++-- .../WhiteIsZero24TiffColor{TPixel}.cs | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T4BitReader.cs b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T4BitReader.cs index c46066a3a8..226bfe5dad 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T4BitReader.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/Decompressors/T4BitReader.cs @@ -434,6 +434,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors /// /// The number of bits to read. /// The value read. + [MethodImpl(InliningOptions.ShortMethod)] protected uint ReadValue(int nBits) { DebugGuard.MustBeGreaterThan(nBits, 0, nameof(nBits)); diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero24TiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero24TiffColor{TPixel}.cs index f384705267..9be8dd7741 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero24TiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero24TiffColor{TPixel}.cs @@ -28,10 +28,10 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation { var color = default(TPixel); color.FromScaledVector4(Vector4.Zero); - byte[] buffer = new byte[4]; + Span buffer = stackalloc byte[4]; int bufferStartIdx = this.isBigEndian ? 1 : 0; - Span bufferSpan = buffer.AsSpan(bufferStartIdx); + Span bufferSpan = buffer.Slice(bufferStartIdx); int offset = 0; for (int y = top; y < top + height; y++) { diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero24TiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero24TiffColor{TPixel}.cs index 73c168a698..d483d7faf8 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero24TiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero24TiffColor{TPixel}.cs @@ -28,11 +28,11 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation { var color = default(TPixel); color.FromScaledVector4(Vector4.Zero); - byte[] buffer = new byte[4]; + Span buffer = stackalloc byte[4]; int bufferStartIdx = this.isBigEndian ? 1 : 0; const uint maxValue = 0xFFFFFF; - Span bufferSpan = buffer.AsSpan(bufferStartIdx); + Span bufferSpan = buffer.Slice(bufferStartIdx); int offset = 0; for (int y = top; y < top + height; y++) {