From c712f98e055caa7a23eedcce1bc8cfe476664453 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sat, 20 Nov 2021 18:17:55 +0100 Subject: [PATCH] Change CodeLengthCodeOrder, LiteralMap and Norm to ReadOnlySpan --- .../Formats/Webp/Lossless/WebpLosslessDecoder.cs | 13 ++++++------- src/ImageSharp/Formats/Webp/WebpLookupTables.cs | 3 ++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs b/src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs index 82fd13c7d..82bd32a02 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/WebpLosslessDecoder.cs @@ -65,15 +65,8 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless FixedTableSize + 2704 }; - private static readonly byte[] CodeLengthCodeOrder = { 17, 18, 0, 1, 2, 3, 4, 5, 16, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; - private static readonly int NumCodeLengthCodes = CodeLengthCodeOrder.Length; - private static readonly byte[] LiteralMap = - { - 0, 1, 1, 1, 0 - }; - /// /// Initializes a new instance of the class. /// @@ -87,6 +80,12 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless this.configuration = configuration; } + // This uses C#'s compiler optimization to refer to assembly's static data directly. + private static ReadOnlySpan CodeLengthCodeOrder => new byte[] { 17, 18, 0, 1, 2, 3, 4, 5, 16, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; + + // This uses C#'s compiler optimization to refer to assembly's static data directly. + private static ReadOnlySpan LiteralMap => new byte[] { 0, 1, 1, 1, 0 }; + /// /// Decodes the image from the stream using the bitreader. /// diff --git a/src/ImageSharp/Formats/Webp/WebpLookupTables.cs b/src/ImageSharp/Formats/Webp/WebpLookupTables.cs index bf47b01bc..c89411435 100644 --- a/src/ImageSharp/Formats/Webp/WebpLookupTables.cs +++ b/src/ImageSharp/Formats/Webp/WebpLookupTables.cs @@ -239,7 +239,8 @@ namespace SixLabors.ImageSharp.Formats.Webp } }; - public static readonly byte[] Norm = + // This uses C#'s compiler optimization to refer to assembly's static data directly. + public static ReadOnlySpan Norm => new byte[] { // renorm_sizes[i] = 8 - log2(i) 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,