mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:07:34 +00:00
Userland: Change static const variables to static constexpr
`static const` variables can be computed and initialized at run-time during initialization or the first time a function is called. Change them to `static constexpr` to ensure they are computed at compile-time. This allows some removal of `strlen` because the length of the `StringView` can be used which is pre-computed at compile-time.
This commit is contained in:
parent
31515a9147
commit
f912a48315
23 changed files with 111 additions and 82 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<StringView, 7> 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<StringView, 7> short_day_names = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
||||
static constexpr Array<StringView, 7> mini_day_names = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" };
|
||||
static constexpr Array<StringView, 7> micro_day_names = { "S", "M", "T", "W", "T", "F", "S" };
|
||||
|
||||
static const char* long_month_names[] = {
|
||||
static constexpr Array<StringView, 12> long_month_names = {
|
||||
"January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December"
|
||||
};
|
||||
|
||||
static const char* short_month_names[] = {
|
||||
static constexpr Array<StringView, 12> short_month_names = {
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||
};
|
||||
|
|
|
@ -16,9 +16,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))
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Array.h>
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibCore/ConfigFile.h>
|
||||
|
@ -178,7 +180,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 } };
|
||||
static constexpr Array<IconSection, 2> 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) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Alex McGrath <amk@amk.ie>
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -48,7 +49,7 @@ void LinkLabel::set_hovered(bool hover)
|
|||
|
||||
void LinkLabel::mousemove_event(MouseEvent& event)
|
||||
{
|
||||
static const int extra_target_width = 3;
|
||||
constexpr int extra_target_width = 3;
|
||||
set_hovered(event.position().x() <= font().width(text()) + extra_target_width);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue