String optimizations

This commit is contained in:
Marco De Araujo 2026-01-12 11:49:37 -04:00
parent 6109785e63
commit 3929a4a277
2 changed files with 13 additions and 13 deletions

View file

@ -1,3 +1,4 @@
use std::borrow::Cow;
use std::cmp::min; use std::cmp::min;
use crate::i18n::t; use crate::i18n::t;
@ -52,12 +53,7 @@ pub fn render_monitor_list(main_frame: &mut Frame, area: Rect, state: &mut Dashb
height: visible_height as u16, height: visible_height as u16,
}; };
render_group( render_group(main_frame, group_area, group, half > rendered_height);
main_frame,
group_area,
group,
half > rendered_height ,
);
current_y += visible_height; current_y += visible_height;
rendered_height += visible_height; rendered_height += visible_height;
@ -178,10 +174,14 @@ fn create_monitor_item(monitor: &MonitorViewState) -> Row<'_> {
let status_icon = get_status_emoji(&monitor.status); let status_icon = get_status_emoji(&monitor.status);
let status_color = get_status_color(&monitor.status); let status_color = get_status_color(&monitor.status);
let display_name: String = if monitor.name.len() > MAX_NAME_LENGTH { let display_name: Cow<str> = if monitor.name.len() > MAX_NAME_LENGTH {
format!("{:.width$}...", &monitor.name, width = MAX_NAME_LENGTH - 3) Cow::Owned(format!(
"{:.width$}...",
monitor.name,
width = MAX_NAME_LENGTH - 3
))
} else { } else {
monitor.name.clone() Cow::Borrowed(&monitor.name)
}; };
let response_text = format!("{:>7}ms", monitor.response_time); let response_text = format!("{:>7}ms", monitor.response_time);
@ -191,7 +191,7 @@ fn create_monitor_item(monitor: &MonitorViewState) -> Row<'_> {
Row::new(vec![ Row::new(vec![
get_formated_line(format!("{} ", status_icon), status_color, Modifier::empty()), get_formated_line(format!("{} ", status_icon), status_color, Modifier::empty()),
get_formated_line(display_name, Color::White, Modifier::empty()), get_formated_line(display_name.to_string(), Color::White, Modifier::empty()),
get_formated_line(response_text, Color::Cyan, Modifier::empty()), get_formated_line(response_text, Color::Cyan, Modifier::empty()),
get_formated_line(uptime_text, Color::Magenta, Modifier::empty()), get_formated_line(uptime_text, Color::Magenta, Modifier::empty()),
status_line_spans, status_line_spans,

View file

@ -3,7 +3,7 @@ use crate::data::heartbeat::model::HeartbeatEntry;
use crate::i18n::t; use crate::i18n::t;
use ratatui::widgets::ScrollbarState; use ratatui::widgets::ScrollbarState;
use rayon::prelude::*; use rayon::prelude::*;
use std::borrow::Cow;
pub const BORDER_LINES_VIEW: usize = 3; pub const BORDER_LINES_VIEW: usize = 3;
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
@ -15,7 +15,7 @@ pub enum MonitorStatus {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct MonitorViewState { pub struct MonitorViewState {
pub name: String, pub name: Cow<'static, str>,
pub status: MonitorStatus, pub status: MonitorStatus,
pub response_time: String, pub response_time: String,
pub uptime_24h: String, pub uptime_24h: String,
@ -141,7 +141,7 @@ fn add_monitor_view_state(group: UnifiedGroupData) -> Vec<MonitorViewState> {
.unwrap_or_else(|| t("unknown").to_string()); .unwrap_or_else(|| t("unknown").to_string());
MonitorViewState { MonitorViewState {
name: monitor.name, name: Cow::Owned(monitor.name),
status, status,
response_time, response_time,
uptime_24h, uptime_24h,