diff options
| author | Tanapol Prucksakorn <me@tanapol.dev> | 2025-07-23 00:03:44 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-22 17:03:44 +0200 |
| commit | ee933744dd3812670e3f2d7dc8b6d5c01aafb8f2 (patch) | |
| tree | 530e98676f2621a406d0952561af44f017c98e78 | |
| parent | fix(plugins): multiple-select + compact-bar tooltip multiplayer issues (#4312) (diff) | |
| download | sl0ppij-ee933744dd3812670e3f2d7dc8b6d5c01aafb8f2.tar.gz sl0ppij-ee933744dd3812670e3f2d7dc8b6d5c01aafb8f2.tar.xz sl0ppij-ee933744dd3812670e3f2d7dc8b6d5c01aafb8f2.zip | |
performance(server): Improve dump_screen! performance (#2548)
* Pre-allocates `buf` string.
* Uses `trim_end_matches()` instead of regex.
Co-authored-by: Tanapol Prucksakorn <tanapol.pr@gmail.com>
| -rw-r--r-- | zellij-server/src/panes/grid.rs | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/zellij-server/src/panes/grid.rs b/zellij-server/src/panes/grid.rs index c12815c4..c60bcbc1 100644 --- a/zellij-server/src/panes/grid.rs +++ b/zellij-server/src/panes/grid.rs @@ -272,7 +272,7 @@ fn subtract_isize_from_usize(u: usize, i: isize) -> usize { macro_rules! dump_screen { ($lines:expr) => {{ let mut is_first = true; - let mut buf = "".to_owned(); + let mut buf = String::with_capacity($lines.iter().map(|l| l.len()).sum()); for line in &$lines { if line.is_canonical && !is_first { @@ -281,8 +281,7 @@ macro_rules! dump_screen { let s: String = (&line.columns).into_iter().map(|x| x.character).collect(); // Replace the spaces at the end of the line. Sometimes, the lines are // collected with spaces until the end of the panel. - let re = Regex::new("([^ ])[ ]*$").unwrap(); - buf.push_str(&(re.replace(&s, "${1}"))); + buf.push_str(&s.trim_end_matches(' ')); is_first = false; } buf |
