aboutsummaryrefslogtreecommitdiff
path: root/src/term
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2018-06-16 17:50:44 +0000
committerGitHub <noreply@github.com>2018-06-16 17:50:44 +0000
commitbfd62ef45bedf02a4f61c08bba134a2eb06c0b47 (patch)
treee83f6220aaab971b61c7216a6ea4198ddbd8b165 /src/term
parent4631ca4db5faf10eb0276e3968814a68c86c81ee (diff)
downloadr-alacritty-bfd62ef45bedf02a4f61c08bba134a2eb06c0b47.tar.gz
r-alacritty-bfd62ef45bedf02a4f61c08bba134a2eb06c0b47.tar.bz2
r-alacritty-bfd62ef45bedf02a4f61c08bba134a2eb06c0b47.zip
Optimize indexing of the grid's raw buffer
The `compute_index` method in the `Storage` struct used to normalize indices was responsible for a significant amount of the CPU time spent while running the `alt-screen-random-write` benchmark (~50%). The issue with this relatively simple method was that due to how often the method is executed, the modulo operation was too expensive. Instead of the modulo, a more conservative branch has been put in place which has a very efficient best-case (which is hit most of the time). Until now the methods for growing/shrinking the storage buffer and compute_index have been written with the assumption that `self.zero` might be bigger than `self.inner.len()`. However there is no reason why `self.zero` wouldn't be constrained to always be within the size of the raw buffer, so this has been changed to make things a little simpler and more explicit. Instead of clamping the selection to be within the buffer inside the storage, this is now checked in the selection logic to remove all selection-specific logic from `storage.rs`.
Diffstat (limited to 'src/term')
-rw-r--r--src/term/mod.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/term/mod.rs b/src/term/mod.rs
index 8635c818..6de8afac 100644
--- a/src/term/mod.rs
+++ b/src/term/mod.rs
@@ -945,9 +945,12 @@ impl Term {
fn append(
&mut self,
grid: &Grid<Cell>,
- line: usize,
+ mut line: usize,
cols: Range<Column>
) -> Option<Range<Column>> {
+ // Select until last line still within the buffer
+ line = min(line, grid.len() - 1);
+
let grid_line = &grid[line];
let line_length = grid_line.line_length();
let line_end = min(line_length, cols.end + 1);