Skip to content

Commit 88850a6

Browse files
author
Stephan Dilly
committed
improve log drawing performance
1 parent 38e0038 commit 88850a6

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/tabs/revlog/mod.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use tui::{
2323
};
2424
use utils::{ItemBatch, LogEntry};
2525

26-
static ELEMENTS_PER_LINE: usize = 10;
2726
static SLICE_SIZE: usize = 1200;
2827
///
2928
pub struct Revlog {
@@ -169,7 +168,8 @@ impl Revlog {
169168
tags: Option<String>,
170169
theme: &Theme,
171170
) {
172-
let count_before = txt.len();
171+
const ELEMENTS_PER_LINE: usize = 10;
172+
173173
txt.reserve(ELEMENTS_PER_LINE);
174174

175175
let splitter_txt = Cow::from(" ");
@@ -205,24 +205,29 @@ impl Revlog {
205205
theme.text(true, selected),
206206
));
207207
txt.push(Text::Raw(Cow::from("\n")));
208-
209-
assert_eq!(txt.len() - count_before, ELEMENTS_PER_LINE);
210208
}
211209

212-
fn get_text(&self) -> Vec<Text> {
210+
fn get_text(&self, height: usize) -> Vec<Text> {
213211
let selection = self.relative_selection();
214212

215213
let mut txt = Vec::new();
216214

217-
for (idx, e) in self.items.items.iter().enumerate() {
215+
for (idx, e) in self
216+
.items
217+
.items
218+
.iter()
219+
.skip(self.scroll_top)
220+
.take(height)
221+
.enumerate()
222+
{
218223
let tag = if let Some(tags) = self.tags.get(&e.hash) {
219224
Some(tags.join(" "))
220225
} else {
221226
None
222227
};
223228
Self::add_entry(
224229
e,
225-
idx == selection,
230+
idx + self.scroll_top == selection,
226231
&mut txt,
227232
tag,
228233
&self.theme,
@@ -261,20 +266,15 @@ impl DrawableComponent for Revlog {
261266
);
262267

263268
f.render_widget(
264-
Paragraph::new(
265-
self.get_text()
266-
.iter()
267-
.skip(self.scroll_top * ELEMENTS_PER_LINE)
268-
.take(height_in_lines * ELEMENTS_PER_LINE),
269-
)
270-
.block(
271-
Block::default()
272-
.borders(Borders::ALL)
273-
.title(title.as_str())
274-
.border_style(self.theme.block(true))
275-
.title_style(self.theme.title(true)),
276-
)
277-
.alignment(Alignment::Left),
269+
Paragraph::new(self.get_text(height_in_lines).iter())
270+
.block(
271+
Block::default()
272+
.borders(Borders::ALL)
273+
.title(title.as_str())
274+
.border_style(self.theme.block(true))
275+
.title_style(self.theme.title(true)),
276+
)
277+
.alignment(Alignment::Left),
278278
area,
279279
);
280280
}

0 commit comments

Comments
 (0)