summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2023-07-01 03:28:23 -0400
committerGitHub <noreply@github.com>2023-07-01 03:28:23 -0400
commit3f53818c54502bcfa02a920ed7b8d288b5edf201 (patch)
treebc189032a33b6af24f97b7af078a1a5167f0e3c5
parentdce30ee882195b5e0a5a1971067b7279227eba7e (diff)
other: remove some unnecessary vec allocations (#1234)
* other: remove unnecessary vector allocations in farmer * other: remove unnecessary vector allocations when drawing tui Rows
-rw-r--r--src/app/data_farmer.rs8
-rw-r--r--src/canvas/widgets/battery_display.rs19
-rw-r--r--src/canvas/widgets/network_graph.rs4
3 files changed, 14 insertions, 17 deletions
diff --git a/src/app/data_farmer.rs b/src/app/data_farmer.rs
index d1db6070..37e58229 100644
--- a/src/app/data_farmer.rs
+++ b/src/app/data_farmer.rs
@@ -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;
}
}
diff --git a/src/canvas/widgets/battery_display.rs b/src/canvas/widgets/battery_display.rs
index 6c175d39..5e579a9c 100644
--- a/src/canvas/widgets/battery_display.rs
+++ b/src/canvas/widgets/battery_display.rs
@@ -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,
);
diff --git a/src/canvas/widgets/network_graph.rs b/src/canvas/widgets/network_graph.rs
index bfbe3582..5e6f71d1 100644
--- a/src/canvas/widgets/network_graph.rs
+++ b/src/canvas/widgets/network_graph.rs
@@ -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