From 15737d7d10c4144d614df3b58c96c7f3f6ef8ba4 Mon Sep 17 00:00:00 2001 From: Thomas Linford Date: Wed, 30 Aug 2023 10:46:06 +0200 Subject: [PATCH] fix(grid): memory leak with unfocused tabs (#2745) * use hashset instead of vec for changed lines avoid output buffer growring indefinitely if tab does not get rendered * tidy up - improve hashset -> vec conversion - remove now unnecessary dedup * use copied instead of cloned on iter --- zellij-server/src/output/mod.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/zellij-server/src/output/mod.rs b/zellij-server/src/output/mod.rs index 6f2b295b..3750ecc6 100644 --- a/zellij-server/src/output/mod.rs +++ b/zellij-server/src/output/mod.rs @@ -829,14 +829,14 @@ impl CharacterChunk { #[derive(Clone, Debug)] pub struct OutputBuffer { - pub changed_lines: Vec, // line index + pub changed_lines: HashSet, // line index pub should_update_all_lines: bool, } impl Default for OutputBuffer { fn default() -> Self { OutputBuffer { - changed_lines: vec![], + changed_lines: HashSet::new(), should_update_all_lines: true, // first time we should do a full render } } @@ -845,14 +845,14 @@ impl Default for OutputBuffer { impl OutputBuffer { pub fn update_line(&mut self, line_index: usize) { if !self.should_update_all_lines { - self.changed_lines.push(line_index); + self.changed_lines.insert(line_index); } } pub fn update_lines(&mut self, start: usize, end: usize) { if !self.should_update_all_lines { for idx in start..=end { if !self.changed_lines.contains(&idx) { - self.changed_lines.push(idx); + self.changed_lines.insert(idx); } } } @@ -885,9 +885,8 @@ impl OutputBuffer { } changed_chunks } else { - let mut line_changes = self.changed_lines.to_vec(); + let mut line_changes: Vec<_> = self.changed_lines.iter().copied().collect(); line_changes.sort_unstable(); - line_changes.dedup(); let mut changed_chunks = Vec::new(); for line_index in line_changes { let terminal_characters =