diff options
author | Thomas Linford <tlinford@users.noreply.github.com> | 2023-08-30 10:46:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-30 10:46:06 +0200 |
commit | 15737d7d10c4144d614df3b58c96c7f3f6ef8ba4 (patch) | |
tree | 1a33ec5adb83530b13726668801bfcaba062cbdf | |
parent | 1988206792006c8bd6ead554423c18e508f32f6b (diff) |
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
-rw-r--r-- | zellij-server/src/output/mod.rs | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/zellij-server/src/output/mod.rs b/zellij-server/src/output/mod.rs index 6f2b295bb..3750ecc6a 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<usize>, // line index + pub changed_lines: HashSet<usize>, // 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 = |