From 800ea8ea969835297dc7e7da345a45b9dc5e751a Mon Sep 17 00:00:00 2001 From: Lenny Maiorani Date: Wed, 19 May 2021 09:32:07 -0600 Subject: 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`. --- Userland/Libraries/LibGfx/Painter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Userland/Libraries/LibGfx/Painter.cpp') diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index 89bec0cf58..1ccbbdcf43 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -1476,7 +1476,7 @@ void do_draw_text(const IntRect& rect, const TextType& text, const Font& font, T lines.append(line); } - static const int line_spacing = 4; + constexpr int line_spacing = 4; int line_height = font.glyph_height() + line_spacing; IntRect bounding_rect { 0, 0, 0, (static_cast(lines.size()) * line_height) - line_spacing }; -- cgit v1.2.3