1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-18 13:55:23 -05:00

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.
This commit is contained in:
Christian Duerr 2018-05-01 20:07:59 +02:00
parent 946ef1e306
commit 0853fafe48
No known key found for this signature in database
GPG key ID: 85CDAE3C164BA7B4
2 changed files with 12 additions and 18 deletions

View file

@ -114,17 +114,7 @@ pub enum Scroll {
impl<T: Copy + Clone> Grid<T> { impl<T: Copy + Clone> Grid<T> {
pub fn new(lines: index::Line, cols: index::Column, scrollback: usize, template: T) -> 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); let raw = Storage::with_capacity(*lines + scrollback, lines, Row::new(cols, &template));
// 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));
}
Grid { Grid {
raw, raw,
cols, cols,

View file

@ -36,9 +36,18 @@ impl<T: PartialEq> ::std::cmp::PartialEq for Storage<T> {
impl<T> Storage<T> { impl<T> Storage<T> {
#[inline] #[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 { Storage {
inner: Vec::with_capacity(cap), inner,
zero: 0, zero: 0,
visible_lines: lines - 1, visible_lines: lines - 1,
len: cap, len: cap,
@ -89,11 +98,6 @@ impl<T> Storage<T> {
self.visible_lines = next - 1; self.visible_lines = next - 1;
} }
#[inline]
pub fn push(&mut self, item: T) {
self.inner.push(item)
}
#[inline] #[inline]
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.len self.len