aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2018-02-11 10:07:33 -0800
committerJoe Wilm <joe@jwilm.com>2018-02-11 10:07:33 -0800
commit620f83842cafc77d7da0915d7fbac6cac484d9a0 (patch)
tree95afefead9aa71e8ee92346314efcb9f937ec477
parentb7578a5236902aa8d10ba4c1b43041699dfe9b15 (diff)
downloadalacritty-vec-deque-backing.tar.gz
alacritty-vec-deque-backing.zip
Minor improvementsvec-deque-backing
-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> {