mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:07:45 +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
|
@ -5,6 +5,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Array.h>
|
||||
#include <LibCore/DateTime.h>
|
||||
#include <LibGUI/Calendar.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
|
@ -16,21 +17,21 @@ REGISTER_WIDGET(GUI, Calendar);
|
|||
|
||||
namespace GUI {
|
||||
|
||||
static const char* long_day_names[] = {
|
||||
static constexpr Array long_day_names = {
|
||||
"Sunday", "Monday", "Tuesday", "Wednesday",
|
||||
"Thursday", "Friday", "Saturday"
|
||||
};
|
||||
|
||||
static const char* short_day_names[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
||||
static const char* mini_day_names[] = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" };
|
||||
static const char* micro_day_names[] = { "S", "M", "T", "W", "T", "F", "S" };
|
||||
static constexpr Array short_day_names = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
||||
static constexpr Array mini_day_names = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" };
|
||||
static constexpr Array micro_day_names = { "S", "M", "T", "W", "T", "F", "S" };
|
||||
|
||||
static const char* long_month_names[] = {
|
||||
static constexpr Array long_month_names = {
|
||||
"January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December"
|
||||
};
|
||||
|
||||
static const char* short_month_names[] = {
|
||||
static constexpr Array short_month_names = {
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||
};
|
||||
|
|
|
@ -15,9 +15,9 @@ REGISTER_WIDGET(GUI, CheckBox)
|
|||
|
||||
namespace GUI {
|
||||
|
||||
static const int s_box_width = 13;
|
||||
static const int s_box_height = 13;
|
||||
static const int s_horizontal_padding = 6;
|
||||
static constexpr int s_box_width = 13;
|
||||
static constexpr int s_box_height = 13;
|
||||
static constexpr int s_horizontal_padding = 6;
|
||||
|
||||
CheckBox::CheckBox(String text)
|
||||
: AbstractButton(move(text))
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
namespace GUI {
|
||||
|
||||
static const char* s_arrow_bitmap_data = {
|
||||
static constexpr char s_arrow_bitmap_data[] = {
|
||||
" "
|
||||
" # "
|
||||
" ## "
|
||||
|
@ -24,8 +24,8 @@ static const char* s_arrow_bitmap_data = {
|
|||
" # "
|
||||
" "
|
||||
};
|
||||
static const int s_arrow_bitmap_width = 9;
|
||||
static const int s_arrow_bitmap_height = 9;
|
||||
static constexpr int s_arrow_bitmap_width = 9;
|
||||
static constexpr int s_arrow_bitmap_height = 9;
|
||||
|
||||
ColumnsView::ColumnsView()
|
||||
{
|
||||
|
|
|
@ -169,7 +169,10 @@ Icon FileIconProvider::icon_for_executable(const String& path)
|
|||
int image_size;
|
||||
};
|
||||
|
||||
static const IconSection icon_sections[] = { { .section_name = "serenity_icon_s", .image_size = 16 }, { .section_name = "serenity_icon_m", .image_size = 32 } };
|
||||
constexpr Array icon_sections = {
|
||||
IconSection { .section_name = "serenity_icon_s", .image_size = 16 },
|
||||
IconSection { .section_name = "serenity_icon_m", .image_size = 32 }
|
||||
};
|
||||
|
||||
bool had_error = false;
|
||||
for (const auto& icon_section : icon_sections) {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
namespace GUI {
|
||||
|
||||
static const char* s_resize_corner_shadows_data = {
|
||||
static constexpr char s_resize_corner_shadows_data[] = {
|
||||
" "
|
||||
" ## "
|
||||
" # "
|
||||
|
@ -31,7 +31,7 @@ static const char* s_resize_corner_shadows_data = {
|
|||
" "
|
||||
};
|
||||
|
||||
static const char* s_resize_corner_highlights_data = {
|
||||
static constexpr char s_resize_corner_highlights_data[] = {
|
||||
" "
|
||||
" "
|
||||
" # "
|
||||
|
@ -52,8 +52,8 @@ static const char* s_resize_corner_highlights_data = {
|
|||
|
||||
static Gfx::CharacterBitmap* s_resize_corner_shadows_bitmap;
|
||||
static Gfx::CharacterBitmap* s_resize_corner_highlights_bitmap;
|
||||
static const int s_resize_corner_bitmap_width = 16;
|
||||
static const int s_resize_corner_bitmap_height = 16;
|
||||
static constexpr int s_resize_corner_bitmap_width = 16;
|
||||
static constexpr int s_resize_corner_bitmap_height = 16;
|
||||
|
||||
ResizeCorner::ResizeCorner()
|
||||
{
|
||||
|
|
|
@ -15,7 +15,7 @@ REGISTER_WIDGET(GUI, Scrollbar)
|
|||
|
||||
namespace GUI {
|
||||
|
||||
static const char* s_up_arrow_bitmap_data = {
|
||||
static constexpr char s_up_arrow_bitmap_data[] = {
|
||||
" "
|
||||
" # "
|
||||
" ### "
|
||||
|
@ -27,7 +27,7 @@ static const char* s_up_arrow_bitmap_data = {
|
|||
" "
|
||||
};
|
||||
|
||||
static const char* s_down_arrow_bitmap_data = {
|
||||
static constexpr char s_down_arrow_bitmap_data[] = {
|
||||
" "
|
||||
" ### "
|
||||
" ### "
|
||||
|
@ -39,7 +39,7 @@ static const char* s_down_arrow_bitmap_data = {
|
|||
" "
|
||||
};
|
||||
|
||||
static const char* s_left_arrow_bitmap_data = {
|
||||
static constexpr char s_left_arrow_bitmap_data[] = {
|
||||
" "
|
||||
" # "
|
||||
" ## "
|
||||
|
@ -51,7 +51,7 @@ static const char* s_left_arrow_bitmap_data = {
|
|||
" "
|
||||
};
|
||||
|
||||
static const char* s_right_arrow_bitmap_data = {
|
||||
static constexpr char s_right_arrow_bitmap_data[] = {
|
||||
" "
|
||||
" # "
|
||||
" ## "
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue