1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 16:17:47 +00:00

Everywhere: Add sv suffix to strings relying on StringView(char const*)

Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
This commit is contained in:
sin-ack 2022-07-11 17:32:29 +00:00 committed by Andreas Kling
parent e5f09ea170
commit 3f3f45580a
762 changed files with 8315 additions and 8316 deletions

View file

@ -87,30 +87,30 @@ constexpr int black_key_height = 60;
constexpr int white_key_labels_count = 12;
constexpr Array<StringView, white_key_labels_count> white_key_labels = {
"A",
"S",
"D",
"F",
"G",
"H",
"J",
"K",
"L",
";",
"\'",
"\u23CE", // Return key symbol
"A"sv,
"S"sv,
"D"sv,
"F"sv,
"G"sv,
"H"sv,
"J"sv,
"K"sv,
"L"sv,
";"sv,
"\'"sv,
"\u23CE"sv, // Return key symbol
};
constexpr int black_key_labels_count = 8;
constexpr Array<StringView, black_key_labels_count> black_key_labels = {
"W",
"E",
"T",
"Y",
"U",
"O",
"P",
"]",
"W"sv,
"E"sv,
"T"sv,
"Y"sv,
"U"sv,
"O"sv,
"P"sv,
"]"sv,
};
constexpr int black_key_offsets[] = {

View file

@ -55,11 +55,11 @@ MainWidget::MainWidget(TrackManager& track_manager, AudioPlayerLoop& loop)
void MainWidget::add_track_actions(GUI::Menu& menu)
{
menu.add_action(GUI::Action::create("&Add Track", { Mod_Ctrl, Key_T }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/plus.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
menu.add_action(GUI::Action::create("&Add Track", { Mod_Ctrl, Key_T }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/plus.png"sv).release_value_but_fixme_should_propagate_errors(), [&](auto&) {
m_player_widget->add_track();
}));
menu.add_action(GUI::Action::create("&Next Track", { Mod_Ctrl, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-last.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
menu.add_action(GUI::Action::create("&Next Track", { Mod_Ctrl, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-last.png"sv).release_value_but_fixme_should_propagate_errors(), [&](auto&) {
turn_off_pressed_keys();
m_player_widget->next_track();
turn_on_pressed_keys();

View file

@ -155,19 +155,19 @@ constexpr int beats_per_bar = 4;
constexpr int notes_per_beat = 4;
constexpr int roll_length = (sample_rate / (beats_per_minute / 60)) * beats_per_bar;
constexpr char const* note_names[] = {
"C",
"C#",
"D",
"D#",
"E",
"F",
"F#",
"G",
"G#",
"A",
"A#",
"B",
constexpr StringView note_names[] = {
"C"sv,
"C#"sv,
"D"sv,
"D#"sv,
"E"sv,
"F"sv,
"F#"sv,
"G"sv,
"G#"sv,
"A"sv,
"A#"sv,
"B"sv,
};
// Equal temperament, A = 440Hz

View file

@ -24,12 +24,12 @@ PlayerWidget::PlayerWidget(TrackManager& manager, AudioPlayerLoop& loop)
set_fill_with_background_color(true);
m_track_number_choices.append("1");
m_play_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/play.png").release_value_but_fixme_should_propagate_errors();
m_pause_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/pause.png").release_value_but_fixme_should_propagate_errors();
m_back_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-back.png").release_value_but_fixme_should_propagate_errors(); // Go back a note
m_next_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png").release_value_but_fixme_should_propagate_errors(); // Advance a note
m_add_track_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/plus.png").release_value_but_fixme_should_propagate_errors();
m_next_track_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-last.png").release_value_but_fixme_should_propagate_errors();
m_play_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/play.png"sv).release_value_but_fixme_should_propagate_errors();
m_pause_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/pause.png"sv).release_value_but_fixme_should_propagate_errors();
m_back_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-back.png"sv).release_value_but_fixme_should_propagate_errors(); // Go back a note
m_next_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png"sv).release_value_but_fixme_should_propagate_errors(); // Advance a note
m_add_track_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/plus.png"sv).release_value_but_fixme_should_propagate_errors();
m_next_track_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-last.png"sv).release_value_but_fixme_should_propagate_errors();
RefPtr<GUI::Label> label = add<GUI::Label>("Track");
label->set_max_width(75);

View file

@ -152,7 +152,7 @@ void RollWidget::paint_event(GUI::PaintEvent& event)
}
Gfx::IntRect note_name_rect(3, y, 1, note_height);
char const* note_name = note_names[note % notes_per_octave];
auto note_name = note_names[note % notes_per_octave];
painter.draw_text(note_name_rect, note_name, Gfx::TextAlignment::CenterLeft);
note_name_rect.translate_by(Gfx::FontDatabase::default_font().width(note_name) + 2, 0);

View file

@ -81,7 +81,7 @@ SamplerWidget::SamplerWidget(TrackManager& track_manager)
m_open_button = m_open_button_and_recorded_sample_name_container->add<GUI::Button>();
m_open_button->set_fixed_size(24, 24);
m_open_button->set_focus_policy(GUI::FocusPolicy::TabFocus);
m_open_button->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open.png").release_value_but_fixme_should_propagate_errors());
m_open_button->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open.png"sv).release_value_but_fixme_should_propagate_errors());
m_open_button->on_click = [this](auto) {
Optional<String> open_path = GUI::FilePicker::get_open_filepath(window());
if (!open_path.has_value())

View file

@ -38,7 +38,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto audio_loop = AudioPlayerLoop::construct(track_manager, need_to_write_wav, wav_writer);
auto app_icon = GUI::Icon::default_icon("app-piano");
auto app_icon = GUI::Icon::default_icon("app-piano"sv);
auto window = GUI::Window::construct();
auto main_widget = TRY(window->try_set_main_widget<MainWidget>(track_manager, audio_loop));
window->set_title("Piano");
@ -51,13 +51,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
main_widget_updater->start();
auto& file_menu = window->add_menu("&File");
file_menu.add_action(GUI::Action::create("Export", { Mod_Ctrl, Key_E }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/file-export.png")), [&](const GUI::Action&) {
file_menu.add_action(GUI::Action::create("Export", { Mod_Ctrl, Key_E }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/file-export.png"sv)), [&](const GUI::Action&) {
save_path = GUI::FilePicker::get_save_filepath(window, "Untitled", "wav");
if (!save_path.has_value())
return;
wav_writer.set_file(save_path.value());
if (wav_writer.has_error()) {
GUI::MessageBox::show(window, String::formatted("Failed to export WAV file: {}", wav_writer.error_string()), "Error", GUI::MessageBox::Type::Error);
GUI::MessageBox::show(window, String::formatted("Failed to export WAV file: {}", wav_writer.error_string()), "Error"sv, GUI::MessageBox::Type::Error);
wav_writer.clear_error();
return;
}