diff options
author | Christian Duerr <contact@christianduerr.com> | 2020-12-10 02:10:24 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-10 02:10:24 +0000 |
commit | 4975be29df848db9b339b5390290e4eb2ac8e140 (patch) | |
tree | dc5d1f3782fba964684c7e95146b9b146ba15553 /alacritty_terminal/src/grid/storage.rs | |
parent | e924c8441da3d0b439da292067961aecc120fd08 (diff) | |
download | alacritty-4975be29df848db9b339b5390290e4eb2ac8e140.tar.gz alacritty-4975be29df848db9b339b5390290e4eb2ac8e140.zip |
Fix scrolling region performance with fixed lines
This resolves an issue with Alacritty's scrolling region performance
when there's a number of fixed lines at the top of the screen. This
affects commonly used applications like tmux or vim.
Instead of using separate logic for when the scrolling region starts at
the top of the screen without any fixed lines, the code should now try
to figure out the target position of these fixed lines ahead of time,
swap them into place and still perform the optimized implementation to
move the grid.
This comes with the small trade-off that since lines are swapped before
rotating the screen without clearing or removing any lines during the
rotation process, that the places the fixed lines have been swapped with
will appear out of order when using scrolling regions in the primary
screen buffer. Since the use of scrolling regions primarily affects the
alternate screen and most terminals don't keep any history at all, this
should however not cause any problems.
Diffstat (limited to 'alacritty_terminal/src/grid/storage.rs')
-rw-r--r-- | alacritty_terminal/src/grid/storage.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/alacritty_terminal/src/grid/storage.rs b/alacritty_terminal/src/grid/storage.rs index dd8dbb22..96c578b3 100644 --- a/alacritty_terminal/src/grid/storage.rs +++ b/alacritty_terminal/src/grid/storage.rs @@ -12,9 +12,9 @@ const MAX_CACHE_SIZE: usize = 1_000; /// A ring buffer for optimizing indexing and rotation. /// -/// The [`Storage::rotate`] and [`Storage::rotate_up`] functions are fast modular additions on the -/// internal [`zero`] field. As compared with [`slice::rotate_left`] which must rearrange items in -/// memory. +/// The [`Storage::rotate`] and [`Storage::rotate_down`] functions are fast modular additions on +/// the internal [`zero`] field. As compared with [`slice::rotate_left`] which must rearrange items +/// in memory. /// /// As a consequence, both [`Index`] and [`IndexMut`] are reimplemented for this type to account /// for the zeroth element not always being at the start of the allocation. @@ -186,16 +186,16 @@ impl<T> Storage<T> { debug_assert!(count.abs() as usize <= self.inner.len()); let len = self.inner.len(); - self.zero = (self.zero as isize + count + len as isize) as usize % self.inner.len(); + self.zero = (self.zero as isize + count + len as isize) as usize % len; } - /// Rotate the grid up, moving all existing lines down in history. + /// Rotate all existing lines down in history. /// /// This is a faster, specialized version of [`rotate_left`]. /// /// [`rotate_left`]: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.rotate_left #[inline] - pub fn rotate_up(&mut self, count: usize) { + pub fn rotate_down(&mut self, count: usize) { self.zero = (self.zero + count) % self.inner.len(); } |