diff options
| author | Daniel Jankowski <daniel.jankowski@rub.de> | 2023-12-17 14:33:32 +0100 |
|---|---|---|
| committer | Daniel Jankowski <daniel.jankowski@rub.de> | 2023-12-17 14:33:32 +0100 |
| commit | aa67d6fbecab9a45b6044f019adb303bc84d63fe (patch) | |
| tree | b29760b80a67a44d274c62936b41c3ccc484c95d /src | |
| parent | feat: perf + mem optimization of rendering (diff) | |
| download | sl0pstatus-aa67d6fbecab9a45b6044f019adb303bc84d63fe.tar.gz sl0pstatus-aa67d6fbecab9a45b6044f019adb303bc84d63fe.tar.xz sl0pstatus-aa67d6fbecab9a45b6044f019adb303bc84d63fe.zip | |
feat: further perf + mem optimization of widgets
Diffstat (limited to 'src')
| -rw-r--r-- | src/frames.rs | 10 | ||||
| -rw-r--r-- | src/widgets/command.rs | 4 | ||||
| -rw-r--r-- | src/widgets/mode.rs | 42 | ||||
| -rw-r--r-- | src/widgets/tabs.rs | 16 |
4 files changed, 37 insertions, 35 deletions
diff --git a/src/frames.rs b/src/frames.rs index dc3d30d..d43a0e4 100644 --- a/src/frames.rs +++ b/src/frames.rs @@ -5,7 +5,7 @@ pub fn hide_frames_on_single_pane( pane_info: PaneManifest, plugin_pane_id: PluginIds, ) { - let panes = match get_current_panes(tabs, pane_info) { + let panes = match get_current_panes(&tabs, &pane_info) { Some(panes) => panes, None => return, }; @@ -13,7 +13,7 @@ pub fn hide_frames_on_single_pane( // check if we are running for the current tab since one plugin will run for // each tab. If we do not prevent execution, the screen will start to flicker // 'cause every plugin will try to toggle the frames - if !is_plugin_for_current_tab(panes.clone(), plugin_pane_id) { + if !is_plugin_for_current_tab(&panes, plugin_pane_id) { return; } @@ -37,7 +37,7 @@ pub fn hide_frames_on_single_pane( } } -fn is_plugin_for_current_tab(panes: Vec<PaneInfo>, plugin_pane_id: PluginIds) -> bool { +fn is_plugin_for_current_tab(panes: &[PaneInfo], plugin_pane_id: PluginIds) -> bool { let plugin_pane = panes .iter() .find(|p| p.is_plugin && p.id == plugin_pane_id.plugin_id); @@ -45,12 +45,12 @@ fn is_plugin_for_current_tab(panes: Vec<PaneInfo>, plugin_pane_id: PluginIds) -> plugin_pane.is_some() } -fn get_current_panes(tabs: Vec<TabInfo>, pane_info: PaneManifest) -> Option<Vec<PaneInfo>> { +fn get_current_panes(tabs: &[TabInfo], pane_info: &PaneManifest) -> Option<Vec<PaneInfo>> { let active_tab = tabs.iter().find(|t| t.active); let active_tab = active_tab.as_ref()?; pane_info .panes .get(&active_tab.position) - .map(|p| (*p).clone()) + .cloned() } diff --git a/src/widgets/command.rs b/src/widgets/command.rs index 8a7a3f8..9d50b50 100644 --- a/src/widgets/command.rs +++ b/src/widgets/command.rs @@ -98,7 +98,7 @@ impl Widget for CommandWidget { fn run_command_if_needed(command_config: CommandConfig, name: &str, state: &ZellijState) { let ts = Local::now(); let last_run = - get_timestamp_from_event_or_default(name, state.clone(), command_config.interval); + get_timestamp_from_event_or_default(name, state, command_config.interval); if ts.timestamp() - last_run.timestamp() >= command_config.interval { let mut context = BTreeMap::new(); @@ -159,7 +159,7 @@ fn parse_config(zj_conf: BTreeMap<String, String>) -> BTreeMap<String, CommandCo fn get_timestamp_from_event_or_default( name: &str, - state: ZellijState, + state: &ZellijState, interval: i64, ) -> DateTime<Local> { let command_result = state.command_results.get(name); diff --git a/src/widgets/mode.rs b/src/widgets/mode.rs index 0937b50..61dda75 100644 --- a/src/widgets/mode.rs +++ b/src/widgets/mode.rs @@ -118,18 +118,20 @@ impl ModeWidget { impl Widget for ModeWidget { fn process(&self, _name: &str, state: &ZellijState) -> String { self.select_format(state.mode.mode) - .iter_mut() + .iter() .map(|f| { + let mut content = f.content.clone(); + if f.content.contains("{name}") { - f.content = f + content = f .content .replace("{name}", format!("{:?}", state.mode.mode).as_str()); } - f + (f, content) }) - .fold("".to_string(), |acc, f| { - format!("{acc}{}", f.format_string(&f.content)) + .fold("".to_string(), |acc, (f, content)| { + format!("{acc}{}", f.format_string(&content)) }) } @@ -137,22 +139,22 @@ impl Widget for ModeWidget { } impl ModeWidget { - fn select_format(&self, mode: InputMode) -> Vec<FormattedPart> { + fn select_format(&self, mode: InputMode) -> &Vec<FormattedPart> { match mode { - InputMode::Normal => self.normal_format.clone(), - InputMode::Locked => self.locked_format.clone(), - InputMode::Resize => self.resize_format.clone(), - InputMode::Pane => self.pane_format.clone(), - InputMode::Tab => self.tab_format.clone(), - InputMode::Scroll => self.scroll_format.clone(), - InputMode::EnterSearch => self.enter_search_format.clone(), - InputMode::Search => self.search_format.clone(), - InputMode::RenameTab => self.rename_tab_format.clone(), - InputMode::RenamePane => self.rename_pane_format.clone(), - InputMode::Session => self.session_format.clone(), - InputMode::Move => self.move_format.clone(), - InputMode::Prompt => self.prompt_format.clone(), - InputMode::Tmux => self.tmux_format.clone(), + InputMode::Normal => &self.normal_format, + InputMode::Locked => &self.locked_format, + InputMode::Resize => &self.resize_format, + InputMode::Pane => &self.pane_format, + InputMode::Tab => &self.tab_format, + InputMode::Scroll => &self.scroll_format, + InputMode::EnterSearch => &self.enter_search_format, + InputMode::Search => &self.search_format, + InputMode::RenameTab => &self.rename_tab_format, + InputMode::RenamePane => &self.rename_pane_format, + InputMode::Session => &self.session_format, + InputMode::Move => &self.move_format, + InputMode::Prompt => &self.prompt_format, + InputMode::Tmux => &self.tmux_format, } } } diff --git a/src/widgets/tabs.rs b/src/widgets/tabs.rs index 8c386d5..569519e 100644 --- a/src/widgets/tabs.rs +++ b/src/widgets/tabs.rs @@ -94,32 +94,32 @@ impl Widget for TabsWidget { } impl TabsWidget { - fn select_format(&self, info: TabInfo) -> Vec<FormattedPart> { + fn select_format(&self, info: &TabInfo) -> &Vec<FormattedPart> { if info.active && info.is_fullscreen_active { - return self.active_tab_fullscreen_format.clone(); + return &self.active_tab_fullscreen_format; } if info.active && info.is_sync_panes_active { - return self.active_tab_sync_format.clone(); + return &self.active_tab_sync_format; } if info.active { - return self.active_tab_format.clone(); + return &self.active_tab_format; } if info.is_fullscreen_active { - return self.normal_tab_fullscreen_format.clone(); + return &self.normal_tab_fullscreen_format; } if info.is_sync_panes_active { - return self.normal_tab_sync_format.clone(); + return &self.normal_tab_sync_format; } - self.normal_tab_format.clone() + &self.normal_tab_format } fn render_tab(&self, tab: &TabInfo) -> String { - let formatters = self.select_format(tab.clone()); + let formatters = self.select_format(tab); let mut output = "".to_string(); for f in formatters.iter() { |
