aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2018-02-11 10:07:33 -0800
committerJoe Wilm <joe@jwilm.com>2018-03-07 09:46:18 -0800
commitdebf6003b5a168f7e1e839d07072bc64cb66f200 (patch)
treec9e71fb486c81bf6685fcafe37e0853158b128e7
parentbe89dbf30be8d9eae9a30226e49a406d0aa6776b (diff)
downloadalacritty-debf6003b5a168f7e1e839d07072bc64cb66f200.tar.gz
alacritty-debf6003b5a168f7e1e839d07072bc64cb66f200.zip
Minor improvements
-rw-r--r--src/grid/mod.rs18
-rw-r--r--src/grid/storage.rs5
2 files changed, 14 insertions, 9 deletions
diff --git a/src/grid/mod.rs b/src/grid/mod.rs
index 8e30915c..0c84530a 100644
--- a/src/grid/mod.rs
+++ b/src/grid/mod.rs
@@ -179,26 +179,26 @@ impl<T: Copy + Clone> Grid<T> {
self.swap_lines(line, line - positions);
}
- for i in IndexRange(Line(0)..positions) {
- self.raw[*(region.start - i - 1)].reset(&self.template_row);
+ for line in IndexRange(region.start .. (region.start + positions)) {
+ self.raw[*line].reset(&self.template_row);
}
}
}
+ /// scroll_up moves lines at the bottom towards the top
+ ///
+ /// This is the performance-sensitive part of scrolling.
#[inline]
pub fn scroll_up(&mut self, region: &Range<index::Line>, positions: index::Line) {
if region.start == Line(0) {
// Rotate the entire line buffer. If there's a scrolling region
// active, the bottom lines are restored in the next step.
- self.raw.rotate(*positions as isize);
+ self.raw.rotate_up(*positions);
// Now, restore any lines outside the scroll region
- let mut i = 0;
- for _ in IndexRange(region.end .. self.num_lines()) {
- let idx = *self.num_lines() - i - 1;
+ for idx in (*region.end .. *self.num_lines()).rev() {
// First do the swap
self.raw.swap(idx, idx - *positions);
- i += 1;
}
// Finally, reset recycled lines
@@ -214,8 +214,8 @@ impl<T: Copy + Clone> Grid<T> {
}
// Clear reused lines
- for i in IndexRange(Line(0)..positions) {
- self.raw[*(region.start - i - 1)].reset(&self.template_row);
+ for line in IndexRange((region.end - positions) .. region.end) {
+ self.raw[*line].reset(&self.template_row);
}
}
}
diff --git a/src/grid/storage.rs b/src/grid/storage.rs
index f5c2d87e..49f3d26c 100644
--- a/src/grid/storage.rs
+++ b/src/grid/storage.rs
@@ -68,6 +68,11 @@ impl<T> Storage<T> {
assert!(count.abs() as usize <= len);
self.zero += (count + len as isize) as usize % len;
}
+
+ // Fast path
+ pub fn rotate_up(&mut self, count: usize) {
+ self.zero = (self.zero + count) % self.len();
+ }
}
impl<T> Index<usize> for Storage<T> {