aboutsummaryrefslogtreecommitdiff
path: root/src/grid/storage.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2018-05-19 14:47:16 -0700
committerJoe Wilm <joe@jwilm.com>2018-06-02 09:56:50 -0700
commit169b87e4ce19f4fd22e5d06ff27f9d3d0ee19b44 (patch)
tree04fbe139a5bda9dbbfb02d9ead2cacea3718f314 /src/grid/storage.rs
parent5a11f8584317b6a949a1ff3a5b3a446766db0665 (diff)
downloadalacritty-169b87e4ce19f4fd22e5d06ff27f9d3d0ee19b44.tar.gz
alacritty-169b87e4ce19f4fd22e5d06ff27f9d3d0ee19b44.zip
Shave a few cycles off Grid::scroll_up
This implementation avoids a few extra transformations by operating in buffer-space. However, there is still a transformation from the logical buffer-space to the underlying vector.
Diffstat (limited to 'src/grid/storage.rs')
-rw-r--r--src/grid/storage.rs28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/grid/storage.rs b/src/grid/storage.rs
index e7c1a307..eb87c622 100644
--- a/src/grid/storage.rs
+++ b/src/grid/storage.rs
@@ -171,12 +171,25 @@ impl<T> Storage<T> {
self.len
}
- /// Compute actual index in underlying storage given the requested index.
#[inline]
+ pub fn raw_len(&self) -> usize {
+ self.inner.len()
+ }
+
+ /// Compute actual index in underlying storage given the requested index.
fn compute_index(&self, requested: usize) -> usize {
(requested + self.zero) % self.inner.len()
}
+ #[inline]
+ pub fn line_offset(&self) -> usize {
+ self.inner.len() + self.zero + *self.visible_lines
+ }
+
+ pub fn compute_line_index(&self, a: Line) -> usize {
+ (self.line_offset() - *a) % self.inner.len()
+ }
+
pub fn swap_lines(&mut self, a: Line, b: Line) {
let offset = self.inner.len() + self.zero + *self.visible_lines;
let a = (offset - *a) % self.inner.len();
@@ -184,6 +197,19 @@ impl<T> Storage<T> {
self.inner.swap(a, b);
}
+ /// Swap two lines in raw buffer
+ ///
+ /// # Panics
+ ///
+ /// `swap` will panic if either `a` or `b` are out-of-bounds of the
+ /// underlying storage.
+ 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);
+ }
+
/// Iterator over *logical* entries in the storage
///
/// This *does not* iterate over hidden entries.