From f50ca1a54c94fe324d22d985c1acae1ff7c16a80 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sat, 21 Jul 2018 17:17:41 +0000 Subject: Scrollback cleanup There were some unneeded codeblocks and TODO/XXX comments in the code that have been removed. All issues marked with TODO/XXX have either been already resolved or tracking issues exist. --- src/grid/mod.rs | 25 ++++++++----------------- src/grid/row.rs | 3 ++- src/grid/storage.rs | 22 ++++++++-------------- src/grid/tests.rs | 4 ++-- 4 files changed, 20 insertions(+), 34 deletions(-) (limited to 'src/grid') diff --git a/src/grid/mod.rs b/src/grid/mod.rs index 949a5ed5..ef587ffd 100644 --- a/src/grid/mod.rs +++ b/src/grid/mod.rs @@ -102,6 +102,7 @@ pub struct GridIterator<'a, T: 'a> { pub cur: Point, } +#[derive(Copy, Clone)] pub enum Scroll { Lines(isize), PageUp, @@ -396,6 +397,7 @@ impl Grid { } } +#[cfg_attr(feature = "cargo-clippy", allow(len_without_is_empty))] impl Grid { #[inline] pub fn num_lines(&self) -> index::Line { @@ -437,15 +439,6 @@ impl Grid { pub fn contains(&self, point: &Point) -> bool { self.lines > point.line && self.cols > point.col } - - // /// Swap two lines in the grid - // /// - // /// This could have used slice::swap internally, but we are able to have - // /// better error messages by doing the bounds checking ourselves. - // #[inline] - // pub fn swap_lines(&mut self, src: index::Line, dst: index::Line) { - // self.raw.swap(*src, *dst); - // } } impl<'a, T> Iterator for GridIterator<'a, T> { @@ -566,10 +559,10 @@ impl<'a, T> RegionMut<'a, T> { pub trait IndexRegion { /// Get an immutable region of Self - fn region<'a>(&'a self, _: I) -> Region<'a, T>; + fn region(&self, _: I) -> Region; /// Get a mutable region of Self - fn region_mut<'a>(&'a mut self, _: I) -> RegionMut<'a, T>; + fn region_mut(&mut self, _: I) -> RegionMut; } impl IndexRegion, T> for Grid { @@ -772,13 +765,11 @@ impl<'a, T: Copy + 'a> Iterator for DisplayIter<'a, T> { // Update line/col to point to next item self.col += 1; - if self.col == self.grid.num_cols() { - if self.offset != self.limit { - self.offset -= 1; + if self.col == self.grid.num_cols() && self.offset != self.limit { + self.offset -= 1; - self.col = Column(0); - self.line = Line(*self.grid.lines - 1 - (self.offset - self.limit)); - } + self.col = Column(0); + self.line = Line(*self.grid.lines - 1 - (self.offset - self.limit)); } item diff --git a/src/grid/row.rs b/src/grid/row.rs index ea8804a7..69a4f2b2 100644 --- a/src/grid/row.rs +++ b/src/grid/row.rs @@ -71,6 +71,7 @@ impl Row { } } +#[cfg_attr(feature = "cargo-clippy", allow(len_without_is_empty))] impl Row { pub fn shrink(&mut self, cols: Column) { while self.len() != *cols { @@ -84,7 +85,7 @@ impl Row { self.inner.len() } - pub fn iter<'a>(&'a self) -> slice::Iter<'a, T> { + pub fn iter(&self) -> slice::Iter { self.inner.iter() } } diff --git a/src/grid/storage.rs b/src/grid/storage.rs index 5d6cb936..6a453da6 100644 --- a/src/grid/storage.rs +++ b/src/grid/storage.rs @@ -68,12 +68,12 @@ impl ::std::cmp::PartialEq for Storage { // Smaller Zero (3): // 7 8 9 | 0 1 2 3 | 4 5 6 // C3 C3 C3 | C1 C1 C1 C1 | C2 C2 C2 - &bigger.inner[bigger_zero..] - == &smaller.inner[smaller_zero..smaller_zero + (len - bigger_zero)] - && &bigger.inner[..bigger_zero - smaller_zero] - == &smaller.inner[smaller_zero + (len - bigger_zero)..] - && &bigger.inner[bigger_zero - smaller_zero..bigger_zero] - == &smaller.inner[..smaller_zero] + bigger.inner[bigger_zero..] + == smaller.inner[smaller_zero..smaller_zero + (len - bigger_zero)] + && bigger.inner[..bigger_zero - smaller_zero] + == smaller.inner[smaller_zero + (len - bigger_zero)..] + && bigger.inner[bigger_zero - smaller_zero..bigger_zero] + == smaller.inner[..smaller_zero] } } @@ -84,11 +84,8 @@ impl Storage { T: Clone, { // Allocate all lines in the buffer, including scrollback history - // - // TODO (jwilm) Allocating each line at this point is expensive and - // delays startup. A nice solution might be having `Row` delay - // allocation until it's actually used. let inner = vec![template; cap]; + Storage { inner, zero: 0, @@ -124,7 +121,7 @@ impl Storage { } /// Grow the number of lines in the buffer, filling new lines with the template - pub fn grow_lines(&mut self, growage: usize, template_row: Row) + fn grow_lines(&mut self, growage: usize, template_row: Row) where T: Clone, { @@ -225,9 +222,6 @@ impl Storage { /// The default implementation from swap generates 8 movups and 4 movaps /// instructions. This implementation achieves the swap in only 8 movups /// instructions. - /// - // TODO Once specialization is available, Storage can be fully generic - // again instead of enforcing inner: Vec>. pub fn swap(&mut self, a: usize, b: usize) { debug_assert!(::std::mem::size_of::>() == 32); diff --git a/src/grid/tests.rs b/src/grid/tests.rs index 435f0c3d..e136e3b3 100644 --- a/src/grid/tests.rs +++ b/src/grid/tests.rs @@ -20,7 +20,7 @@ use index::{Point, Line, Column}; // Scroll up moves lines upwards #[test] fn scroll_up() { - println!(""); + println!(); let mut grid = Grid::new(Line(10), Column(1), 0, 0); for i in 0..10 { @@ -58,7 +58,7 @@ fn scroll_up() { // Scroll down moves lines downwards #[test] fn scroll_down() { - println!(""); + println!(); let mut grid = Grid::new(Line(10), Column(1), 0, 0); for i in 0..10 { -- cgit