diff options
author | Christian Duerr <contact@christianduerr.com> | 2018-05-01 20:07:59 +0200 |
---|---|---|
committer | Christian Duerr <contact@christianduerr.com> | 2018-05-14 19:44:52 +0200 |
commit | 48c10676a42e0908147ec6df1324bc78d0eca8e5 (patch) | |
tree | d4b5e2bd6f537923f7a0bde1cfd9c50e18618bd4 | |
parent | 5de8062e03de62aaacbcf3569522c7fe0bb01739 (diff) | |
download | alacritty-48c10676a42e0908147ec6df1324bc78d0eca8e5.tar.gz alacritty-48c10676a42e0908147ec6df1324bc78d0eca8e5.zip |
Remove `push` from `Storage`
Since every line is allocated at startup anyways, the `push` method on
`Storage` has been removed and instead of pushing to the vector the
initialization has been moved to the `with_capacity` method.
This has the advantage that we don't need to keep track of the `len` in
push (like adding one), but we just need to worry about
growing/shrinking the visible area.
-rw-r--r-- | src/grid/mod.rs | 12 | ||||
-rw-r--r-- | src/grid/storage.rs | 18 |
2 files changed, 12 insertions, 18 deletions
diff --git a/src/grid/mod.rs b/src/grid/mod.rs index 87ac3d05..803f1e6e 100644 --- a/src/grid/mod.rs +++ b/src/grid/mod.rs @@ -118,17 +118,7 @@ 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); - - // Allocate all lines in the buffer, including scrollback history - // - // TODO (jwilm) Allocating each line at this point is expensive and - // delays startup. A nice solution might be having `Row` delay - // allocation until it's actually used. - for _ in 0..raw.len() { - raw.push(Row::new(cols, &template)); - } - + let raw = Storage::with_capacity(*lines + scrollback, lines, Row::new(cols, &template)); Grid { raw, cols, diff --git a/src/grid/storage.rs b/src/grid/storage.rs index a50e8076..1f71b5b5 100644 --- a/src/grid/storage.rs +++ b/src/grid/storage.rs @@ -67,9 +67,18 @@ impl<T: PartialEq> ::std::cmp::PartialEq for Storage<T> { impl<T> Storage<T> { #[inline] - pub fn with_capacity(cap: usize, lines: Line) -> Storage<T> { + pub fn with_capacity(cap: usize, lines: Line, template: T) -> Storage<T> + where + T: Clone, + { + // Allocate all lines in the buffer, including scrollback history + // + // TODO (jwilm) Allocating each line at this point is expensive and + // delays startup. A nice solution might be having `Row` delay + // allocation until it's actually used. + let inner = vec![template; cap]; Storage { - inner: Vec::with_capacity(cap), + inner, zero: 0, visible_lines: lines - 1, len: cap, @@ -121,11 +130,6 @@ impl<T> Storage<T> { } #[inline] - pub fn push(&mut self, item: T) { - self.inner.push(item) - } - - #[inline] pub fn len(&self) -> usize { self.len } |