diff options
author | Joe Wilm <joe@jwilm.com> | 2016-08-22 08:37:50 -0700 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-08-22 08:37:50 -0700 |
commit | 3c5d46c8518fb6a1a6e1679ba3a2cc8815f37d3c (patch) | |
tree | 887dca71dcd533ee68b0f68837700903eef52325 /src/util.rs | |
parent | b325afe8d2d67a72e14f436fec2158e822db4e8e (diff) | |
download | alacritty-3c5d46c8518fb6a1a6e1679ba3a2cc8815f37d3c.tar.gz alacritty-3c5d46c8518fb6a1a6e1679ba3a2cc8815f37d3c.zip |
Scrolling v2
The previous scrolling + scroll region implementation exhibited display
corruption bugs in several applications including tmux, irssi, htop, and
vim. The new implementation doesn't seem to suffer from any of those
issues.
This implementation is able to `find /usr` on my machine (nearly 600k
lines) in ~2.0 seconds while st is able to do the same in ~2.2 seconds.
Alacritty is officially faster!
Diffstat (limited to 'src/util.rs')
-rw-r--r-- | src/util.rs | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/src/util.rs b/src/util.rs index 805acea6..693e26a8 100644 --- a/src/util.rs +++ b/src/util.rs @@ -24,80 +24,3 @@ pub mod thread { ::std::thread::Builder::new().name(name.into()).spawn(f).expect("thread spawn works") } } - -/// Types that can have their elements rotated -pub trait Rotate { - fn rotate(&mut self, positions: isize); -} - -impl<T> Rotate for [T] { - fn rotate(&mut self, positions: isize) { - // length is needed over and over - let len = self.len(); - - // Enforce positions in [0, len) and treat negative rotations as a - // posititive rotation of len - positions. - let positions = if positions > 0 { - positions as usize % len - } else { - len - (-positions as usize) % len - }; - - // If positions is 0 or the entire slice, it's a noop. - if positions == 0 || positions == len { - return; - } - - self[..positions].reverse(); - self[positions..].reverse(); - self.reverse(); - } -} - - -#[cfg(test)] -mod tests { - use super::Rotate; - - #[test] - fn rotate_forwards_works() { - let s = &mut [1, 2, 3, 4, 5]; - s.rotate(1); - assert_eq!(&[2, 3, 4, 5, 1], s); - } - - #[test] - fn rotate_backwards_works() { - let s = &mut [1, 2, 3, 4, 5]; - s.rotate(-1); - assert_eq!(&[5, 1, 2, 3, 4], s); - } - - #[test] - fn rotate_multiple_forwards() { - let s = &mut [1, 2, 3, 4, 5, 6, 7]; - s.rotate(2); - assert_eq!(&[3, 4, 5, 6, 7, 1, 2], s); - } - - #[test] - fn rotate_multiple_backwards() { - let s = &mut [1, 2, 3, 4, 5]; - s.rotate(-3); - assert_eq!(&[3, 4, 5, 1, 2], s); - } - - #[test] - fn rotate_forwards_overflow() { - let s = &mut [1, 2, 3, 4, 5]; - s.rotate(6); - assert_eq!(&[2, 3, 4, 5, 1], s); - } - - #[test] - fn rotate_backwards_overflow() { - let s = &mut [1, 2, 3, 4, 5]; - s.rotate(-6); - assert_eq!(&[5, 1, 2, 3, 4], s); - } -} |