From a352099b050fe53e83e1863e9eef1ccefce39f2c Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 2 Feb 2024 21:48:31 -0500 Subject: [PATCH] LibGfx/ICC: In lerp_nd(), use VLAs for left_index, factor `x.size()` is 3 or 4 in practice and at most 15 in theory (cf `number_of_components_in_color_space()` in Profile.cpp), so using a VLA for these should be fine from a stack size PoV. They're accessed from two local loops iterating from 0 to `x.size()`, so it's hopefully not too risky from a security PoV either. Takes Build/lagom/bin/image --no-output \ --assign-color-profile \ Build/lagom/Root/res/icc/Adobe/CMYK/USWebCoatedSWOP.icc \ --convert-to-color-profile serenity-sRGB.icc \ cmyk.jpg from 2.81s to 2.74s on my machine, about 2.5% faster. --- Userland/Libraries/LibGfx/ICC/TagTypes.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibGfx/ICC/TagTypes.h b/Userland/Libraries/LibGfx/ICC/TagTypes.h index 7fa00d4b2c..83acd786b4 100644 --- a/Userland/Libraries/LibGfx/ICC/TagTypes.h +++ b/Userland/Libraries/LibGfx/ICC/TagTypes.h @@ -37,13 +37,13 @@ float lerp_1d(ReadonlySpan values, float x) // `sample()` gets a vector where 0 <= i'th coordinate < size(i) and should return the value of the look-up table at that position. inline FloatVector3 lerp_nd(Function size, Function const&)> sample, Vector const& x) { - Vector left_index; - Vector factor; + unsigned left_index[x.size()]; + float factor[x.size()]; for (size_t i = 0; i < x.size(); ++i) { unsigned n = size(i) - 1; float ec = x[i] * n; - left_index.append(min(static_cast(ec), n - 1)); - factor.append(ec - left_index[i]); + left_index[i] = min(static_cast(ec), n - 1); + factor[i] = ec - left_index[i]; } FloatVector3 sample_output {};