summaryrefslogtreecommitdiff
path: root/alacritty_terminal
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2019-12-13 00:57:23 +0100
committerGitHub <noreply@github.com>2019-12-13 00:57:23 +0100
commitcb99fd4e4c16e8fe5c36e8be6062658842794ac3 (patch)
treef771162bea918003ffd8dad49b200358fd0cfd67 /alacritty_terminal
parente99057b179cbdc0851c36575dd043fcdaa45437a (diff)
downloadalacritty-cb99fd4e4c16e8fe5c36e8be6062658842794ac3.tar.gz
alacritty-cb99fd4e4c16e8fe5c36e8be6062658842794ac3.zip
Fix storage rotation error
This fixes a regression introduced in e99057b179cbdc0851c36575dd043fcdaa45437a, which used `self.len` to calculate the remainder of `self.zero` during rotation instead of `self.inner.len()`, leading to a broken `self.zero` offset and incorrect rotation.
Diffstat (limited to 'alacritty_terminal')
-rw-r--r--alacritty_terminal/src/grid/storage.rs30
1 files changed, 14 insertions, 16 deletions
diff --git a/alacritty_terminal/src/grid/storage.rs b/alacritty_terminal/src/grid/storage.rs
index 71b0e025..f754acdc 100644
--- a/alacritty_terminal/src/grid/storage.rs
+++ b/alacritty_terminal/src/grid/storage.rs
@@ -205,7 +205,18 @@ impl<T> Storage<T> {
#[inline]
fn compute_index(&self, requested: usize) -> usize {
debug_assert!(requested < self.len);
- self.wrap_index(self.zero + requested)
+
+ let zeroed = self.zero + requested;
+
+ // Use if/else instead of remainder here to improve performance.
+ //
+ // Requires `zeroed` to be smaller than `self.inner.len() * 2`,
+ // but both `self.zero` and `requested` are always smaller than `self.inner.len()`.
+ if zeroed >= self.inner.len() {
+ zeroed - self.inner.len()
+ } else {
+ zeroed
+ }
}
pub fn swap_lines(&mut self, a: Line, b: Line) {
@@ -254,7 +265,7 @@ 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.len;
+ self.zero = (self.zero as isize + count + len as isize) as usize % self.inner.len();
}
/// Rotate the grid up, moving all existing lines down in history.
@@ -262,7 +273,7 @@ impl<T> Storage<T> {
/// This is a faster, specialized version of [`rotate`].
#[inline]
pub fn rotate_up(&mut self, count: usize) {
- self.zero = self.wrap_index(self.zero + count);
+ self.zero = (self.zero + count) % self.inner.len();
}
/// Drain all rows in the grid.
@@ -277,19 +288,6 @@ impl<T> Storage<T> {
self.inner = vec;
self.zero = 0;
}
-
- /// Wrap index to be within the inner buffer.
- ///
- /// This uses if/else instead of the remainder to improve performance,
- /// so the assumption is made that `index < self.inner.len() * 2`.
- #[inline]
- fn wrap_index(&self, index: usize) -> usize {
- if index >= self.inner.len() {
- index - self.inner.len()
- } else {
- index
- }
- }
}
impl<T> Index<usize> for Storage<T> {