From 8168d85a21b1a67b9cf25808c4e3e01f7437b50d Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sat, 28 Apr 2018 16:15:21 +0200 Subject: Improve storage comparison algorithm Instead of iterating over the raw storage vector because the offsets don't allow direct comparison, the comparison is now done in chunks. Based on benchmarking this is a lot more efficient than using split_off + append or iterating over the elements of the buffer. The `history_size` field has also been removed from the storage structure because it can be easily calculated by substracting the number of visible lines from the length of the raw storage vector. --- src/grid/mod.rs | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'src/grid/mod.rs') diff --git a/src/grid/mod.rs b/src/grid/mod.rs index b6cff604..f3c8ea79 100644 --- a/src/grid/mod.rs +++ b/src/grid/mod.rs @@ -52,23 +52,13 @@ impl Deref for Indexed { impl ::std::cmp::PartialEq for Grid { fn eq(&self, other: &Self) -> bool { - // Compare raw grid content - // TODO: This is pretty inefficient but only used in tests - let mut raw_match = true; - for i in 0..(self.lines.0 + self.history_size) { - for j in 0..self.cols.0 { - if self[i][Column(j)] != other[i][Column(j)] { - raw_match = false; - break; - } - } - } - // Compare struct fields and check result of grid comparison - self.cols.eq(&other.cols) && + self.raw.eq(&other.raw) && + self.cols.eq(&other.cols) && self.lines.eq(&other.lines) && - self.history_size.eq(&other.history_size) && - raw_match + self.display_offset.eq(&other.display_offset) && + self.scroll_limit.eq(&other.scroll_limit) && + self.selection.eq(&other.selection) } } @@ -102,10 +92,6 @@ pub struct Grid { /// Selected region #[serde(skip)] pub selection: Option, - - /// Maximum number of lines in the scrollback history - #[serde(default)] - history_size: usize, } pub struct GridIterator<'a, T: 'a> { @@ -150,7 +136,6 @@ impl Grid { display_offset: 0, scroll_limit: 0, selection: None, - history_size: scrollback, } } @@ -426,6 +411,12 @@ impl Grid { self.scroll_limit = 0; } + /// Total number of lines in the buffer, this includes scrollback + visible lines + #[inline] + pub fn len(&self) -> usize { + self.raw.len() + } + pub fn iter_from(&self, point: Point) -> GridIterator { GridIterator { grid: self, -- cgit