mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-22 20:23:12 +00:00
other: remove some unnecessary vec allocations (#1234)
* other: remove unnecessary vector allocations in farmer * other: remove unnecessary vector allocations when drawing tui Rows
This commit is contained in:
parent
dce30ee882
commit
3f53818c54
3 changed files with 14 additions and 17 deletions
|
@ -318,7 +318,7 @@ impl DataCollection {
|
|||
cpu.iter()
|
||||
.for_each(|cpu| new_entry.cpu_data.push(cpu.cpu_usage));
|
||||
|
||||
self.cpu_harvest = cpu.to_vec();
|
||||
self.cpu_harvest = cpu;
|
||||
}
|
||||
|
||||
fn eat_load_avg(&mut self, load_avg: cpu::LoadAvgHarvest, new_entry: &mut TimedData) {
|
||||
|
@ -328,14 +328,12 @@ impl DataCollection {
|
|||
}
|
||||
|
||||
fn eat_temp(&mut self, temperature_sensors: Vec<temperature::TempHarvest>) {
|
||||
// TODO: [PO] To implement
|
||||
self.temp_harvest = temperature_sensors.to_vec();
|
||||
self.temp_harvest = temperature_sensors;
|
||||
}
|
||||
|
||||
fn eat_disks(
|
||||
&mut self, disks: Vec<disks::DiskHarvest>, io: disks::IoHarvest, harvested_time: Instant,
|
||||
) {
|
||||
// TODO: [PO] To implement
|
||||
let time_since_last_harvest = harvested_time
|
||||
.duration_since(self.current_instant)
|
||||
.as_secs_f64();
|
||||
|
@ -457,6 +455,6 @@ impl DataCollection {
|
|||
gpu.iter().for_each(|data| {
|
||||
new_entry.gpu_data.push(data.1.use_percent);
|
||||
});
|
||||
self.gpu_harvest = gpu.to_vec();
|
||||
self.gpu_harvest = gpu;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,7 +164,7 @@ impl Painter {
|
|||
}
|
||||
|
||||
let mut battery_rows = Vec::with_capacity(4);
|
||||
battery_rows.push(Row::new(vec![
|
||||
battery_rows.push(Row::new([
|
||||
Cell::from("Charge %").style(self.colours.text_style),
|
||||
Cell::from(bars).style(if charge_percentage < 10.0 {
|
||||
self.colours.low_battery_colour
|
||||
|
@ -175,12 +175,12 @@ impl Painter {
|
|||
}),
|
||||
]));
|
||||
battery_rows.push(
|
||||
Row::new(vec!["Rate", &battery_details.watt_consumption])
|
||||
Row::new(["Rate", &battery_details.watt_consumption])
|
||||
.style(self.colours.text_style),
|
||||
);
|
||||
|
||||
battery_rows.push(
|
||||
Row::new(vec!["State", &battery_details.state]).style(self.colours.text_style),
|
||||
Row::new(["State", &battery_details.state]).style(self.colours.text_style),
|
||||
);
|
||||
|
||||
let mut s: String; // Keep string in scope.
|
||||
|
@ -191,20 +191,20 @@ impl Painter {
|
|||
s = long_time(*secs);
|
||||
|
||||
if half_width as usize > s.len() {
|
||||
battery_rows.push(Row::new(vec!["Time to empty", &s]).style(style));
|
||||
battery_rows.push(Row::new(["Time to empty", &s]).style(style));
|
||||
} else {
|
||||
s = short_time(*secs);
|
||||
battery_rows.push(Row::new(vec!["To empty", &s]).style(style));
|
||||
battery_rows.push(Row::new(["To empty", &s]).style(style));
|
||||
}
|
||||
}
|
||||
BatteryDuration::ToFull(secs) => {
|
||||
s = long_time(*secs);
|
||||
|
||||
if half_width as usize > s.len() {
|
||||
battery_rows.push(Row::new(vec!["Time to full", &s]).style(style));
|
||||
battery_rows.push(Row::new(["Time to full", &s]).style(style));
|
||||
} else {
|
||||
s = short_time(*secs);
|
||||
battery_rows.push(Row::new(vec!["To full", &s]).style(style));
|
||||
battery_rows.push(Row::new(["To full", &s]).style(style));
|
||||
}
|
||||
}
|
||||
BatteryDuration::Empty
|
||||
|
@ -214,15 +214,14 @@ impl Painter {
|
|||
}
|
||||
|
||||
battery_rows.push(
|
||||
Row::new(vec!["Health %", &battery_details.health])
|
||||
.style(self.colours.text_style),
|
||||
Row::new(["Health %", &battery_details.health]).style(self.colours.text_style),
|
||||
);
|
||||
|
||||
// Draw
|
||||
f.render_widget(
|
||||
Table::new(battery_rows)
|
||||
.block(battery_block)
|
||||
.header(Row::new(vec![""]).bottom_margin(table_gap))
|
||||
.header(Row::new([""]).bottom_margin(table_gap))
|
||||
.widths(&[Constraint::Percentage(50), Constraint::Percentage(50)]),
|
||||
margined_draw_loc,
|
||||
);
|
||||
|
|
|
@ -178,7 +178,7 @@ impl Painter {
|
|||
let total_tx_display = &app_state.converted_data.total_tx_display;
|
||||
|
||||
// Gross but I need it to work...
|
||||
let total_network = vec![Row::new(vec![
|
||||
let total_network = vec![Row::new([
|
||||
Text::styled(rx_display, self.colours.rx_style),
|
||||
Text::styled(tx_display, self.colours.tx_style),
|
||||
Text::styled(total_rx_display, self.colours.total_rx_style),
|
||||
|
@ -188,7 +188,7 @@ impl Painter {
|
|||
// Draw
|
||||
f.render_widget(
|
||||
Table::new(total_network)
|
||||
.header(Row::new(NETWORK_HEADERS.to_vec()).style(self.colours.table_header_style))
|
||||
.header(Row::new(NETWORK_HEADERS).style(self.colours.table_header_style))
|
||||
.block(Block::default().borders(Borders::ALL).border_style(
|
||||
if app_state.current_widget.widget_id == widget_id {
|
||||
self.colours.highlighted_border_style
|
||||
|
|
Loading…
Reference in a new issue