1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:57:44 +00:00

HexEditor: Stop allocating a String for every character printed

When we have a single char, we can directly construct a StringView for
it instead, which doesn't require a String allocation.
This commit is contained in:
Sam Atkins 2023-12-31 16:42:41 +00:00 committed by Sam Atkins
parent 63de4d3ada
commit 27adbd1792

View file

@ -724,15 +724,16 @@ void HexEditor::paint_event(GUI::PaintEvent& event)
};
painter.fill_rect(text_background_rect, background_color_text);
auto character = String::formatted("{:c}", isprint(cell_value) ? cell_value : '.').release_value_but_fixme_should_propagate_errors();
if (m_edit_mode == EditMode::Text)
draw_cursor_rect();
char const character = is_ascii_printable(cell_value) ? cell_value : '.';
auto character_sv = StringView { &character, 1 };
if (byte_position == m_position)
painter.draw_text(text_display_rect, character, Gfx::TextAlignment::TopLeft, palette().selection_text());
painter.draw_text(text_display_rect, character_sv, Gfx::TextAlignment::TopLeft, palette().selection_text());
else
painter.draw_text(text_display_rect, character, Gfx::TextAlignment::TopLeft, text_color_text);
painter.draw_text(text_display_rect, character_sv, Gfx::TextAlignment::TopLeft, text_color_text);
}
}
}