Skip to content

Commit

Permalink
Merge pull request #54 from alexmaco/perf
Browse files Browse the repository at this point in the history
Small performance tweak for process list view
  • Loading branch information
bvaisvil committed Jun 18, 2020
2 parents 0c8c654 + 7bd9f04 commit 94c5d86
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/render.rs
Expand Up @@ -157,8 +157,6 @@ fn render_process_table(
return None;
}

let end = process_table_start + display_height;

let procs: Vec<&ZProcess> = process_table
.iter()
.map(|pid| {
Expand All @@ -175,9 +173,12 @@ fn render_process_table(
if area.height < 5 {
return highlighted_process; // not enough space to draw anything
}
let rows: Vec<Vec<String>> = procs
let rows: Vec<(Vec<String>, Option<Style>)> = procs
.iter()
.map(|p| {
.enumerate()
.skip(process_table_start)
.take(display_height)
.map(|(i, p)| {
let cmd_string = if show_paths {
if p.command.len() > 1 {
format!(" - {:}", p.command.join(" "))
Expand Down Expand Up @@ -219,7 +220,14 @@ fn render_process_table(
row.push(format!("{:>4.0}", p.fb_utilization));
}
row.push(format!("{:}{:}", p.name, cmd_string));
row

let style = if i == highlighted_row {
Some(Style::default().fg(Color::Magenta).modifier(Modifier::BOLD))
} else {
None
};

(row, style)
})
.collect();

Expand Down Expand Up @@ -259,18 +267,11 @@ fn render_process_table(
ProcessTableSortOrder::Descending => '↓',
};
header[app.psortby as usize].insert(0, sort_ind); //sort column indicator
let rows = rows.iter().enumerate().filter_map(|(i, r)| {
if i >= process_table_start && i < end {
if highlighted_row == i {
Some(Row::StyledData(
r.iter(),
Style::default().fg(Color::Magenta).modifier(Modifier::BOLD),
))
} else {
Some(Row::Data(r.iter()))
}
let rows_view = rows.iter().map(|(row, style)| {
if let Some(style) = style {
Row::StyledData(row.iter(), *style)
} else {
None
Row::Data(row.iter())
}
});

Expand All @@ -286,7 +287,7 @@ fn render_process_table(
)
};

Table::new(header.into_iter(), rows)
Table::new(header.into_iter(), rows_view)
.block(
Block::default()
.borders(Borders::ALL)
Expand Down

0 comments on commit 94c5d86

Please sign in to comment.