From c4a45bb52107dae91b1ddf8023a2e4ae18812073 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 21 Mar 2024 08:52:04 -0400 Subject: [PATCH] LibGfx/JBIG2: Make compute_context() a function pointer ...instead of a lambda that checks the template on every call. Doesn't make a performance difference locally, but seems maybe nicer? No behavior change. --- .../LibGfx/ImageFormats/JBIG2Loader.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp b/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp index f01c39e98cd..3571fa12109 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp @@ -964,16 +964,17 @@ static ErrorOr> generic_region_decoding_procedure(Gener return result; }; - auto compute_context = [&inputs, &compute_context_0, &compute_context_1, &compute_context_2, &compute_context_3](NonnullOwnPtr const& buffer, int x, int y) -> u16 { - if (inputs.gb_template == 0) - return compute_context_0(buffer, x, y); - if (inputs.gb_template == 1) - return compute_context_1(buffer, x, y); - if (inputs.gb_template == 2) - return compute_context_2(buffer, x, y); + u16 (*compute_context)(NonnullOwnPtr const&, int, int); + if (inputs.gb_template == 0) + compute_context = compute_context_0; + else if (inputs.gb_template == 1) + compute_context = compute_context_1; + else if (inputs.gb_template == 2) + compute_context = compute_context_2; + else { VERIFY(inputs.gb_template == 3); - return compute_context_3(buffer, x, y); - }; + compute_context = compute_context_3; + } // "The values of the pixels in this neighbourhood define a context. Each context has its own adaptive probability estimate // used by the arithmetic coder (see Annex E)."