mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:27:45 +00:00
LibVT: Let Terminal keep history in a circular buffer
This makes Terminal::scroll_up() O(1) instead of O(n) in the size of the history. (It's still O(n) in the size of visible lines.) Reduces time to run `disasm /bin/id` with the default terminal window size from 530ms to 409ms (min-of-5) on my system.
This commit is contained in:
parent
90d9c83067
commit
61060c0da8
2 changed files with 16 additions and 4 deletions
|
@ -52,6 +52,8 @@ void Terminal::clear()
|
|||
void Terminal::clear_including_history()
|
||||
{
|
||||
m_history.clear();
|
||||
m_history_start = 0;
|
||||
|
||||
clear();
|
||||
|
||||
m_client.terminal_history_changed();
|
||||
|
@ -738,9 +740,7 @@ void Terminal::scroll_up()
|
|||
invalidate_cursor();
|
||||
if (m_scroll_region_top == 0) {
|
||||
auto line = move(m_lines.ptr_at(m_scroll_region_top));
|
||||
m_history.append(move(line));
|
||||
while (m_history.size() > max_history_size())
|
||||
m_history.take_first();
|
||||
add_line_to_history(move(line));
|
||||
m_client.terminal_history_changed();
|
||||
}
|
||||
m_lines.remove(m_scroll_region_top);
|
||||
|
|
|
@ -76,7 +76,7 @@ public:
|
|||
Line& line(size_t index)
|
||||
{
|
||||
if (index < m_history.size())
|
||||
return m_history[index];
|
||||
return m_history[(m_history_start + index) % m_history.size()];
|
||||
return m_lines[index - m_history.size()];
|
||||
}
|
||||
const Line& line(size_t index) const
|
||||
|
@ -154,7 +154,19 @@ private:
|
|||
|
||||
TerminalClient& m_client;
|
||||
|
||||
size_t m_history_start = 0;
|
||||
NonnullOwnPtrVector<Line> m_history;
|
||||
void add_line_to_history(NonnullOwnPtr<Line>&& line)
|
||||
{
|
||||
if (m_history.size() < max_history_size()) {
|
||||
ASSERT(m_history_start == 0);
|
||||
m_history.append(move(line));
|
||||
return;
|
||||
}
|
||||
m_history.ptr_at(m_history_start) = move(line);
|
||||
m_history_start = (m_history_start + 1) % m_history.size();
|
||||
}
|
||||
|
||||
NonnullOwnPtrVector<Line> m_lines;
|
||||
|
||||
size_t m_scroll_region_top { 0 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue