diff options
author | Daniel Bertalan <dani@danielbertalan.dev> | 2021-06-05 11:12:00 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-10 17:18:02 +0200 |
commit | 7419569a2ba6d5a285293ae59e98a1e38e3c62e3 (patch) | |
tree | 61eb3d06f9d8f1cc926e990609deea4c92e72bbb /Userland/Libraries/LibVT/Line.cpp | |
parent | 8f8fd9c5a8acf25db12f5f74b4c3802c926b97aa (diff) | |
download | serenity-7419569a2ba6d5a285293ae59e98a1e38e3c62e3.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibVT/Line.cpp')
-rw-r--r-- | Userland/Libraries/LibVT/Line.cpp | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/Userland/Libraries/LibVT/Line.cpp b/Userland/Libraries/LibVT/Line.cpp index d807877f17..30b971b9d9 100644 --- a/Userland/Libraries/LibVT/Line.cpp +++ b/Userland/Libraries/LibVT/Line.cpp @@ -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 }; |