diff options
author | Lenny Maiorani <lenny@colorado.edu> | 2021-05-19 09:32:07 -0600 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-05-21 10:07:06 +0100 |
commit | 800ea8ea969835297dc7e7da345a45b9dc5e751a (patch) | |
tree | 5918276b3f75e73d7f4559f97587a23f652612a5 /Userland/Libraries/LibGfx/JPGLoader.cpp | |
parent | 17ff895e1cbc685b99b22856aed16852b564c1f4 (diff) | |
download | serenity-800ea8ea969835297dc7e7da345a45b9dc5e751a.zip |
Userland: static vs non-static constexpr variables
Problem:
- `static` variables consume memory and sometimes are less
optimizable.
- `static const` variables can be `constexpr`, usually.
- `static` function-local variables require an initialization check
every time the function is run.
Solution:
- If a global `static` variable is only used in a single function then
move it into the function and make it non-`static` and `constexpr`.
- Make all global `static` variables `constexpr` instead of `const`.
- Change function-local `static const[expr]` variables to be just
`constexpr`.
Diffstat (limited to 'Userland/Libraries/LibGfx/JPGLoader.cpp')
-rw-r--r-- | Userland/Libraries/LibGfx/JPGLoader.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/Userland/Libraries/LibGfx/JPGLoader.cpp b/Userland/Libraries/LibGfx/JPGLoader.cpp index 1c2aefc209..d2b80a6f55 100644 --- a/Userland/Libraries/LibGfx/JPGLoader.cpp +++ b/Userland/Libraries/LibGfx/JPGLoader.cpp @@ -861,20 +861,20 @@ static void dequantize(JPGLoadingContext& context, Vector<Macroblock>& macrobloc static void inverse_dct(const JPGLoadingContext& context, Vector<Macroblock>& macroblocks) { - static const float m0 = 2.0 * cos(1.0 / 16.0 * 2.0 * M_PI); - static const float m1 = 2.0 * cos(2.0 / 16.0 * 2.0 * M_PI); - static const float m3 = 2.0 * cos(2.0 / 16.0 * 2.0 * M_PI); - static const float m5 = 2.0 * cos(3.0 / 16.0 * 2.0 * M_PI); - static const float m2 = m0 - m5; - static const float m4 = m0 + m5; - static const float s0 = cos(0.0 / 16.0 * M_PI) / sqrt(8); - static const float s1 = cos(1.0 / 16.0 * M_PI) / 2.0; - static const float s2 = cos(2.0 / 16.0 * M_PI) / 2.0; - static const float s3 = cos(3.0 / 16.0 * M_PI) / 2.0; - static const float s4 = cos(4.0 / 16.0 * M_PI) / 2.0; - static const float s5 = cos(5.0 / 16.0 * M_PI) / 2.0; - static const float s6 = cos(6.0 / 16.0 * M_PI) / 2.0; - static const float s7 = cos(7.0 / 16.0 * M_PI) / 2.0; + const float m0 = 2.0 * cos(1.0 / 16.0 * 2.0 * M_PI); + const float m1 = 2.0 * cos(2.0 / 16.0 * 2.0 * M_PI); + const float m3 = 2.0 * cos(2.0 / 16.0 * 2.0 * M_PI); + const float m5 = 2.0 * cos(3.0 / 16.0 * 2.0 * M_PI); + const float m2 = m0 - m5; + const float m4 = m0 + m5; + const float s0 = cos(0.0 / 16.0 * M_PI) / sqrt(8); + const float s1 = cos(1.0 / 16.0 * M_PI) / 2.0; + const float s2 = cos(2.0 / 16.0 * M_PI) / 2.0; + const float s3 = cos(3.0 / 16.0 * M_PI) / 2.0; + const float s4 = cos(4.0 / 16.0 * M_PI) / 2.0; + const float s5 = cos(5.0 / 16.0 * M_PI) / 2.0; + const float s6 = cos(6.0 / 16.0 * M_PI) / 2.0; + const float s7 = cos(7.0 / 16.0 * M_PI) / 2.0; for (u32 vcursor = 0; vcursor < context.mblock_meta.vcount; vcursor += context.vsample_factor) { for (u32 hcursor = 0; hcursor < context.mblock_meta.hcount; hcursor += context.hsample_factor) { |