From 1a01be2654907cfd272542ed662162e860a6dcc2 Mon Sep 17 00:00:00 2001 From: Thomas Linford Date: Mon, 28 Aug 2023 21:26:45 +0200 Subject: [PATCH 1/3] use hashset instead of vec for changed lines avoid output buffer growring indefinitely if tab does not get rendered --- zellij-server/src/output/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/zellij-server/src/output/mod.rs b/zellij-server/src/output/mod.rs index 6f2b295bbc..d33bde4da8 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,7 +885,7 @@ impl OutputBuffer { } changed_chunks } else { - let mut line_changes = self.changed_lines.to_vec(); + let mut line_changes: Vec<_> = self.changed_lines.clone().into_iter().collect(); line_changes.sort_unstable(); line_changes.dedup(); let mut changed_chunks = Vec::new(); From d354ec677afa80229d4498a59cbcc35200e6e8f0 Mon Sep 17 00:00:00 2001 From: Thomas Linford Date: Wed, 30 Aug 2023 10:04:19 +0200 Subject: [PATCH 2/3] tidy up - improve hashset -> vec conversion - remove now unnecessary dedup --- zellij-server/src/output/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/zellij-server/src/output/mod.rs b/zellij-server/src/output/mod.rs index d33bde4da8..73eb56bd08 100644 --- a/zellij-server/src/output/mod.rs +++ b/zellij-server/src/output/mod.rs @@ -885,9 +885,8 @@ impl OutputBuffer { } changed_chunks } else { - let mut line_changes: Vec<_> = self.changed_lines.clone().into_iter().collect(); + let mut line_changes: Vec<_> = self.changed_lines.iter().cloned().collect(); line_changes.sort_unstable(); - line_changes.dedup(); let mut changed_chunks = Vec::new(); for line_index in line_changes { let terminal_characters = From d29dcc3dfb298b521084d2724e7b7307ec9279c6 Mon Sep 17 00:00:00 2001 From: Thomas Linford Date: Wed, 30 Aug 2023 10:13:55 +0200 Subject: [PATCH 3/3] use copied instead of cloned on iter --- zellij-server/src/output/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zellij-server/src/output/mod.rs b/zellij-server/src/output/mod.rs index 73eb56bd08..3750ecc6a2 100644 --- a/zellij-server/src/output/mod.rs +++ b/zellij-server/src/output/mod.rs @@ -885,7 +885,7 @@ impl OutputBuffer { } changed_chunks } else { - let mut line_changes: Vec<_> = self.changed_lines.iter().cloned().collect(); + let mut line_changes: Vec<_> = self.changed_lines.iter().copied().collect(); line_changes.sort_unstable(); let mut changed_chunks = Vec::new(); for line_index in line_changes {