summaryrefslogtreecommitdiff
path: root/src/grid
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2018-04-02 08:44:54 -0700
committerJoe Wilm <joe@jwilm.com>2018-06-02 09:56:50 -0700
commitb19045da66899999856c6b2cc6707b60c607660a (patch)
tree79e3ebe269f3122b762fe940173a2e1a56eccf38 /src/grid
parentf66e3e457bdda808cc3f994a02fd6f7ce5ba381e (diff)
downloadalacritty-b19045da66899999856c6b2cc6707b60c607660a.tar.gz
alacritty-b19045da66899999856c6b2cc6707b60c607660a.zip
Fix BCE ref tests
BCE was broken in attempt to optimize row clearing. The fix is to revert to passing in the current cursor state when clearing.
Diffstat (limited to 'src/grid')
-rw-r--r--src/grid/mod.rs65
-rw-r--r--src/grid/row.rs6
-rw-r--r--src/grid/storage.rs11
-rw-r--r--src/grid/tests.rs4
4 files changed, 39 insertions, 47 deletions
diff --git a/src/grid/mod.rs b/src/grid/mod.rs
index 3495be1d..faf67772 100644
--- a/src/grid/mod.rs
+++ b/src/grid/mod.rs
@@ -73,17 +73,6 @@ pub struct Grid<T> {
/// Invariant: lines is equivalent to raw.len()
lines: index::Line,
- /// Template row.
- ///
- /// This is used to quickly populate new lines and clear recycled lines
- /// during scroll wrapping.
- #[serde(skip)]
- template_row: Row<T>,
-
- /// Template cell for populating template_row
- #[serde(skip)]
- template: T,
-
/// Offset of displayed area
///
/// If the displayed region isn't at the bottom of the screen, it stays
@@ -126,7 +115,6 @@ pub enum Scroll {
impl<T: Copy + Clone> Grid<T> {
pub fn new(lines: index::Line, cols: index::Column, scrollback: usize, template: T) -> Grid<T> {
let mut raw = Storage::with_capacity(*lines + scrollback, lines);
- let template_row = Row::new(cols, &template);
// Allocate all lines in the buffer, including scrollback history
//
@@ -134,15 +122,13 @@ impl<T: Copy + Clone> Grid<T> {
// delays startup. A nice solution might be having `Row` delay
// allocation until it's actually used.
for _ in 0..raw.capacity() {
- raw.push(template_row.clone());
+ raw.push(Row::new(cols, &template));
}
Grid {
raw,
cols,
lines,
- template_row,
- template,
display_offset: 0,
scroll_limit: 0,
selection: None,
@@ -200,20 +186,25 @@ impl<T: Copy + Clone> Grid<T> {
}
}
- pub fn resize(&mut self, lines: index::Line, cols: index::Column) {
+ pub fn resize(
+ &mut self,
+ lines: index::Line,
+ cols: index::Column,
+ template: &T,
+ ) {
// Check that there's actually work to do and return early if not
if lines == self.lines && cols == self.cols {
return;
}
match self.lines.cmp(&lines) {
- Ordering::Less => self.grow_lines(lines),
+ Ordering::Less => self.grow_lines(lines, template),
Ordering::Greater => self.shrink_lines(lines),
Ordering::Equal => (),
}
match self.cols.cmp(&cols) {
- Ordering::Less => self.grow_cols(cols),
+ Ordering::Less => self.grow_cols(cols, template),
Ordering::Greater => self.shrink_cols(cols),
Ordering::Equal => (),
}
@@ -237,7 +228,11 @@ impl<T: Copy + Clone> Grid<T> {
/// Alacritty takes a different approach. Rather than trying to move with
/// the scrollback, we simply pull additional lines from the back of the
/// buffer in order to populate the new area.
- fn grow_lines(&mut self, new_line_count: index::Line) {
+ fn grow_lines(
+ &mut self,
+ new_line_count: index::Line,
+ template: &T,
+ ) {
let previous_scroll_limit = self.scroll_limit;
let lines_added = new_line_count - self.lines;
@@ -246,21 +241,18 @@ impl<T: Copy + Clone> Grid<T> {
self.lines = new_line_count;
// Add new lines to bottom
- self.scroll_up(&(Line(0)..new_line_count), lines_added);
+ self.scroll_up(&(Line(0)..new_line_count), lines_added, template);
self.scroll_limit = self.scroll_limit.saturating_sub(*lines_added);
}
- fn grow_cols(&mut self, cols: index::Column) {
+ fn grow_cols(&mut self, cols: index::Column, template: &T) {
for row in self.raw.iter_mut() {
- row.grow(cols, &self.template);
+ row.grow(cols, template);
}
// Update self cols
self.cols = cols;
-
- // Also update template_row to be the correct length
- self.template_row.grow(cols, &self.template);
}
/// Remove lines from the visible area
@@ -304,7 +296,12 @@ impl<T: Copy + Clone> Grid<T> {
}
#[inline]
- pub fn scroll_down(&mut self, region: &Range<index::Line>, positions: index::Line) {
+ pub fn scroll_down(
+ &mut self,
+ region: &Range<index::Line>,
+ positions: index::Line,
+ template: &T,
+ ) {
// Whether or not there is a scrolling region active, as long as it
// starts at the top, we can do a full rotation which just involves
// changing the start index.
@@ -328,7 +325,7 @@ impl<T: Copy + Clone> Grid<T> {
// Finally, reset recycled lines
for i in IndexRange(Line(0)..positions) {
- self.raw[i].reset(&self.template_row);
+ self.raw[i].reset(&template);
}
} else {
// Subregion rotation
@@ -337,7 +334,7 @@ impl<T: Copy + Clone> Grid<T> {
}
for line in IndexRange(region.start .. (region.start + positions)) {
- self.raw[line].reset(&self.template_row);
+ self.raw[line].reset(&template);
}
}
}
@@ -346,7 +343,12 @@ impl<T: Copy + Clone> Grid<T> {
///
/// This is the performance-sensitive part of scrolling.
#[inline]
- pub fn scroll_up(&mut self, region: &Range<index::Line>, positions: index::Line) {
+ pub fn scroll_up(
+ &mut self,
+ region: &Range<index::Line>,
+ positions: index::Line,
+ template: &T
+ ) {
if region.start == Line(0) {
// Update display offset when not pinned to active area
if self.display_offset != 0 {
@@ -372,7 +374,7 @@ impl<T: Copy + Clone> Grid<T> {
//
// Recycled lines are just above the end of the scrolling region.
for i in 0..*positions {
- self.raw[region.end - i - 1].reset(&self.template_row);
+ self.raw[region.end - i - 1].reset(&template);
}
} else {
// Subregion rotation
@@ -382,7 +384,7 @@ impl<T: Copy + Clone> Grid<T> {
// Clear reused lines
for line in IndexRange((region.end - positions) .. region.end) {
- self.raw[line].reset(&self.template_row);
+ self.raw[line].reset(&template);
}
}
}
@@ -432,7 +434,6 @@ impl<T> Grid<T> {
}
self.cols = cols;
- self.template_row.shrink(cols);
}
}
diff --git a/src/grid/row.rs b/src/grid/row.rs
index f6b2a20e..f7e4a98a 100644
--- a/src/grid/row.rs
+++ b/src/grid/row.rs
@@ -37,8 +37,10 @@ impl<T: Copy + Clone> Row<T> {
/// Resets contents to the contents of `other`
#[inline]
- pub fn reset(&mut self, other: &Row<T>) {
- self.copy_from_slice(&**other);
+ pub fn reset(&mut self, other: &T) {
+ for item in &mut self.0 {
+ *item = *other;
+ }
}
}
diff --git a/src/grid/storage.rs b/src/grid/storage.rs
index 0f1ba9c5..b620b9c0 100644
--- a/src/grid/storage.rs
+++ b/src/grid/storage.rs
@@ -57,11 +57,6 @@ impl<T> Storage<T> {
}
#[inline]
- pub fn pop(&mut self) -> Option<T> {
- self.inner.pop()
- }
-
- #[inline]
pub fn len(&self) -> usize {
self.inner.len()
}
@@ -76,12 +71,6 @@ impl<T> Storage<T> {
((self.len() + self.zero + *self.visible_lines) - *requested) % self.len()
}
- pub fn swap(&mut self, a: usize, b: usize) {
- let a = self.compute_index(a);
- let b = self.compute_index(b);
- self.inner.swap(a, b);
- }
-
pub fn swap_lines(&mut self, a: Line, b: Line) {
let a = self.compute_line_index(a);
let b = self.compute_line_index(b);
diff --git a/src/grid/tests.rs b/src/grid/tests.rs
index 107e7103..3e229fb6 100644
--- a/src/grid/tests.rs
+++ b/src/grid/tests.rs
@@ -29,7 +29,7 @@ fn scroll_up() {
info!("grid: {:?}", grid);
- grid.scroll_up(&(Line(0)..Line(10)), Line(2));
+ grid.scroll_up(&(Line(0)..Line(10)), Line(2), &0);
info!("grid: {:?}", grid);
@@ -65,7 +65,7 @@ fn scroll_down() {
info!("grid: {:?}", grid);
- grid.scroll_down(&(Line(0)..Line(10)), Line(2));
+ grid.scroll_down(&(Line(0)..Line(10)), Line(2), &0);
info!("grid: {:?}", grid);