mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 21:18:14 +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:
parent
17ff895e1c
commit
800ea8ea96
38 changed files with 192 additions and 184 deletions
|
@ -9,6 +9,7 @@
|
|||
#include "GlyphMapWidget.h"
|
||||
#include "NewFontDialog.h"
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/UnicodeUtils.h>
|
||||
#include <Applications/FontEditor/FontEditorWindowGML.h>
|
||||
#include <LibDesktop/Launcher.h>
|
||||
|
@ -37,19 +38,19 @@
|
|||
#include <LibGfx/TextDirection.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static constexpr int s_pangram_count = 7;
|
||||
static const char* pangrams[s_pangram_count] = {
|
||||
"quick fox jumps nightly above wizard",
|
||||
"five quacking zephyrs jolt my wax bed",
|
||||
"pack my box with five dozen liquor jugs",
|
||||
"quick brown fox jumps over the lazy dog",
|
||||
"waxy and quivering jocks fumble the pizza",
|
||||
"~#:[@_1%]*{$2.3}/4^(5'6\")-&|7+8!=<9,0\\>?;",
|
||||
"byxfjärmat föl gick på duvshowen"
|
||||
};
|
||||
|
||||
static RefPtr<GUI::Window> create_font_preview_window(FontEditorWidget& editor)
|
||||
{
|
||||
constexpr int pangram_count = 7;
|
||||
constexpr StringView pangrams[pangram_count] = {
|
||||
"quick fox jumps nightly above wizard",
|
||||
"five quacking zephyrs jolt my wax bed",
|
||||
"pack my box with five dozen liquor jugs",
|
||||
"quick brown fox jumps over the lazy dog",
|
||||
"waxy and quivering jocks fumble the pizza",
|
||||
"~#:[@_1%]*{$2.3}/4^(5'6\")-&|7+8!=<9,0\\>?;",
|
||||
"byxfjärmat föl gick på duvshowen"
|
||||
};
|
||||
|
||||
auto window = GUI::Window::construct();
|
||||
window->set_window_type(GUI::WindowType::ToolWindow);
|
||||
window->set_title("Font preview");
|
||||
|
@ -94,7 +95,7 @@ static RefPtr<GUI::Window> create_font_preview_window(FontEditorWidget& editor)
|
|||
reload_button.set_fixed_width(22);
|
||||
reload_button.on_click = [&] {
|
||||
static int i = 1;
|
||||
if (i >= s_pangram_count)
|
||||
if (i >= pangram_count)
|
||||
i = 0;
|
||||
preview_textbox.set_text(pangrams[i]);
|
||||
i++;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue