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/GIFLoader.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/GIFLoader.cpp')
-rw-r--r-- | Userland/Libraries/LibGfx/GIFLoader.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/Userland/Libraries/LibGfx/GIFLoader.cpp b/Userland/Libraries/LibGfx/GIFLoader.cpp index d8b60c0dbb..7c1d55ba37 100644 --- a/Userland/Libraries/LibGfx/GIFLoader.cpp +++ b/Userland/Libraries/LibGfx/GIFLoader.cpp @@ -19,10 +19,6 @@ namespace Gfx { -// Row strides and offsets for each interlace pass. -static const int INTERLACE_ROW_STRIDES[] = { 8, 8, 4, 2 }; -static const int INTERLACE_ROW_OFFSETS[] = { 0, 4, 2, 1 }; - struct ImageDescriptor { u16 x { 0 }; u16 y { 0 }; @@ -112,8 +108,8 @@ enum class GIFFormat { static Optional<GIFFormat> decode_gif_header(InputMemoryStream& stream) { - static const char valid_header_87[] = "GIF87a"; - static const char valid_header_89[] = "GIF89a"; + constexpr char valid_header_87[] = "GIF87a"; + constexpr char valid_header_89[] = "GIF89a"; Array<u8, 6> header; stream >> header; @@ -378,6 +374,8 @@ static bool decode_frame(GIFLoadingContext& context, size_t frame_index) if (pixel_index % image.width == 0) { if (image.interlaced) { if (interlace_pass < 4) { + constexpr Array INTERLACE_ROW_STRIDES = { 8, 8, 4, 2 }; + constexpr Array INTERLACE_ROW_OFFSETS = { 0, 4, 2, 1 }; if (row + INTERLACE_ROW_STRIDES[interlace_pass] >= image.height) { ++interlace_pass; if (interlace_pass < 4) |