aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2018-05-18 20:44:54 -0700
committerJoe Wilm <joe@jwilm.com>2018-05-19 11:11:40 -0700
commitc25357c945c781788ea41c6f91d0dfc3d15391fc (patch)
treed88bb7477dc42a23ea0d861e1c38fa43d2b8c1af
parentb12ae5105ac0063b594202682ce6183a64cc708a (diff)
downloadalacritty-c25357c945c781788ea41c6f91d0dfc3d15391fc.tar.gz
alacritty-c25357c945c781788ea41c6f91d0dfc3d15391fc.zip
Optimize Storage::swap_lines
Saves a few cycles in a *very* hot function.
-rw-r--r--src/grid/storage.rs14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/grid/storage.rs b/src/grid/storage.rs
index 885cb94c..cadd4e29 100644
--- a/src/grid/storage.rs
+++ b/src/grid/storage.rs
@@ -176,13 +176,10 @@ impl<T> Storage<T> {
(requested + self.zero) % self.inner.len()
}
- fn compute_line_index(&self, requested: Line) -> usize {
- ((self.inner.len() + self.zero + *self.visible_lines) - *requested) % self.inner.len()
- }
-
pub fn swap_lines(&mut self, a: Line, b: Line) {
- let a = self.compute_line_index(a);
- let b = self.compute_line_index(b);
+ let offset = self.inner.len() + self.zero + *self.visible_lines;
+ let a = (offset - *a) % self.inner.len();
+ let b = (offset - *b) % self.inner.len();
self.inner.swap(a, b);
}
@@ -191,9 +188,10 @@ impl<T> Storage<T> {
}
pub fn rotate(&mut self, count: isize) {
+ debug_assert!(count.abs() as usize <= self.inner.len());
+
let len = self.inner.len();
- assert!(count.abs() as usize <= len);
- self.zero += (count + len as isize) as usize % len;
+ self.zero = (self.zero as isize + count + len as isize) as usize % len;
}
// Fast path