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

Kernel+LibVT: Add function for deleting a range of characters

Previously, this was done by telling the client to put a space at each
character in the range. This was inefficient, because a large number of
function calls took place and incorrect, as the ANSI standard dictates
that character attributes should be cleared as well.

The newly added `clear_in_line` function solves this issue. It performs
just one bounds check when it's called and can be implemented as a
pretty tight loop.
This commit is contained in:
Daniel Bertalan 2021-06-05 11:12:00 +02:00 committed by Andreas Kling
parent 8f8fd9c5a8
commit 7419569a2b
7 changed files with 60 additions and 53 deletions

View file

@ -25,15 +25,12 @@ void Line::set_length(size_t new_length)
m_cells.resize(new_length);
}
void Line::clear(const Attribute& attribute)
void Line::clear_range(size_t first_column, size_t last_column, const Attribute& attribute)
{
if (m_dirty) {
for (auto& cell : m_cells) {
cell = Cell { .code_point = ' ', .attribute = attribute };
}
return;
}
for (auto& cell : m_cells) {
VERIFY(first_column <= last_column);
VERIFY(last_column < m_cells.size());
for (size_t i = first_column; i <= last_column; ++i) {
auto& cell = m_cells[i];
if (!m_dirty)
m_dirty = cell.code_point != ' ' || cell.attribute != attribute;
cell = Cell { .code_point = ' ', .attribute = attribute };