From 9ff010188698d8e88781b72e4fbfe19d26e7d2ff Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 25 Aug 2026 10:50:19 +1000 Subject: [PATCH] Use static data for HEVC CABAC transitions --- src/ImageSharp/Formats/Heif/Hevc/HevcCabacContext.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp/Formats/Heif/Hevc/HevcCabacContext.cs b/src/ImageSharp/Formats/Heif/Hevc/HevcCabacContext.cs index 4e7f42501..a2b2cd611 100644 --- a/src/ImageSharp/Formats/Heif/Hevc/HevcCabacContext.cs +++ b/src/ImageSharp/Formats/Heif/Hevc/HevcCabacContext.cs @@ -11,7 +11,9 @@ internal struct HevcCabacContext /// /// Maps each packed context state to the state that follows its most-probable symbol. /// - private static readonly byte[] MostProbableStateTransitions = + // ReadOnlySpan allows the compiler to embed both normative tables in static data instead of allocating + // mutable arrays when this type is initialized. + private static ReadOnlySpan MostProbableStateTransitions => [ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, @@ -26,7 +28,7 @@ internal struct HevcCabacContext /// /// Maps each packed context state to the state that follows its least-probable symbol. /// - private static readonly byte[] LeastProbableStateTransitions = + private static ReadOnlySpan LeastProbableStateTransitions => [ 1, 0, 0, 1, 2, 3, 4, 5, 4, 5, 8, 9, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 18, 19, 22, 23, 22, 23, 24, 25,