aboutsummaryrefslogtreecommitdiff
path: root/src/grid/mod.rs
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2018-04-28 16:15:21 +0200
committerJoe Wilm <jwilm@users.noreply.github.com>2018-05-14 09:50:12 -0700
commit8d3497ba3e89a5e0f6227869b7b320052524fbb2 (patch)
treef42664be1d5ed93b7499849c4e90f1328ed51f7c /src/grid/mod.rs
parent915c9c55f01d7d2c623a325e1b6900e450e84857 (diff)
downloadalacritty-8d3497ba3e89a5e0f6227869b7b320052524fbb2.tar.gz
alacritty-8d3497ba3e89a5e0f6227869b7b320052524fbb2.zip
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.
Diffstat (limited to 'src/grid/mod.rs')
-rw-r--r--src/grid/mod.rs31
1 files changed, 11 insertions, 20 deletions
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<T> Deref for Indexed<T> {
impl<T: PartialEq> ::std::cmp::PartialEq for Grid<T> {
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<T> {
/// Selected region
#[serde(skip)]
pub selection: Option<Selection>,
-
- /// Maximum number of lines in the scrollback history
- #[serde(default)]
- history_size: usize,
}
pub struct GridIterator<'a, T: 'a> {
@@ -150,7 +136,6 @@ impl<T: Copy + Clone> Grid<T> {
display_offset: 0,
scroll_limit: 0,
selection: None,
- history_size: scrollback,
}
}
@@ -426,6 +411,12 @@ impl<T> Grid<T> {
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<usize>) -> GridIterator<T> {
GridIterator {
grid: self,