1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:57:44 +00:00

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`.
This commit is contained in:
Lenny Maiorani 2021-05-19 09:32:07 -06:00 committed by Linus Groh
parent 17ff895e1c
commit 800ea8ea96
38 changed files with 192 additions and 184 deletions

View file

@ -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)