mirror of
https://github.com/ClementTsang/bottom.git
synced 2024-09-11 11:46:59 +03: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
@ -318,7 +318,7 @@ impl DataCollection {
|
|||||||
cpu.iter()
|
cpu.iter()
|
||||||
.for_each(|cpu| new_entry.cpu_data.push(cpu.cpu_usage));
|
.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) {
|
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>) {
|
fn eat_temp(&mut self, temperature_sensors: Vec<temperature::TempHarvest>) {
|
||||||
// TODO: [PO] To implement
|
self.temp_harvest = temperature_sensors;
|
||||||
self.temp_harvest = temperature_sensors.to_vec();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eat_disks(
|
fn eat_disks(
|
||||||
&mut self, disks: Vec<disks::DiskHarvest>, io: disks::IoHarvest, harvested_time: Instant,
|
&mut self, disks: Vec<disks::DiskHarvest>, io: disks::IoHarvest, harvested_time: Instant,
|
||||||
) {
|
) {
|
||||||
// TODO: [PO] To implement
|
|
||||||
let time_since_last_harvest = harvested_time
|
let time_since_last_harvest = harvested_time
|
||||||
.duration_since(self.current_instant)
|
.duration_since(self.current_instant)
|
||||||
.as_secs_f64();
|
.as_secs_f64();
|
||||||
@ -457,6 +455,6 @@ impl DataCollection {
|
|||||||
gpu.iter().for_each(|data| {
|
gpu.iter().for_each(|data| {
|
||||||
new_entry.gpu_data.push(data.1.use_percent);
|
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);
|
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("Charge %").style(self.colours.text_style),
|
||||||
Cell::from(bars).style(if charge_percentage < 10.0 {
|
Cell::from(bars).style(if charge_percentage < 10.0 {
|
||||||
self.colours.low_battery_colour
|
self.colours.low_battery_colour
|
||||||
@ -175,12 +175,12 @@ impl Painter {
|
|||||||
}),
|
}),
|
||||||
]));
|
]));
|
||||||
battery_rows.push(
|
battery_rows.push(
|
||||||
Row::new(vec!["Rate", &battery_details.watt_consumption])
|
Row::new(["Rate", &battery_details.watt_consumption])
|
||||||
.style(self.colours.text_style),
|
.style(self.colours.text_style),
|
||||||
);
|
);
|
||||||
|
|
||||||
battery_rows.push(
|
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.
|
let mut s: String; // Keep string in scope.
|
||||||
@ -191,20 +191,20 @@ impl Painter {
|
|||||||
s = long_time(*secs);
|
s = long_time(*secs);
|
||||||
|
|
||||||
if half_width as usize > s.len() {
|
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 {
|
} else {
|
||||||
s = short_time(*secs);
|
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) => {
|
BatteryDuration::ToFull(secs) => {
|
||||||
s = long_time(*secs);
|
s = long_time(*secs);
|
||||||
|
|
||||||
if half_width as usize > s.len() {
|
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 {
|
} else {
|
||||||
s = short_time(*secs);
|
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
|
BatteryDuration::Empty
|
||||||
@ -214,15 +214,14 @@ impl Painter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
battery_rows.push(
|
battery_rows.push(
|
||||||
Row::new(vec!["Health %", &battery_details.health])
|
Row::new(["Health %", &battery_details.health]).style(self.colours.text_style),
|
||||||
.style(self.colours.text_style),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
f.render_widget(
|
f.render_widget(
|
||||||
Table::new(battery_rows)
|
Table::new(battery_rows)
|
||||||
.block(battery_block)
|
.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)]),
|
.widths(&[Constraint::Percentage(50), Constraint::Percentage(50)]),
|
||||||
margined_draw_loc,
|
margined_draw_loc,
|
||||||
);
|
);
|
||||||
|
@ -178,7 +178,7 @@ impl Painter {
|
|||||||
let total_tx_display = &app_state.converted_data.total_tx_display;
|
let total_tx_display = &app_state.converted_data.total_tx_display;
|
||||||
|
|
||||||
// Gross but I need it to work...
|
// 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(rx_display, self.colours.rx_style),
|
||||||
Text::styled(tx_display, self.colours.tx_style),
|
Text::styled(tx_display, self.colours.tx_style),
|
||||||
Text::styled(total_rx_display, self.colours.total_rx_style),
|
Text::styled(total_rx_display, self.colours.total_rx_style),
|
||||||
@ -188,7 +188,7 @@ impl Painter {
|
|||||||
// Draw
|
// Draw
|
||||||
f.render_widget(
|
f.render_widget(
|
||||||
Table::new(total_network)
|
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(
|
.block(Block::default().borders(Borders::ALL).border_style(
|
||||||
if app_state.current_widget.widget_id == widget_id {
|
if app_state.current_widget.widget_id == widget_id {
|
||||||
self.colours.highlighted_border_style
|
self.colours.highlighted_border_style
|
||||||
|
Loading…
Reference in New Issue
Block a user