Performance optimization

This commit is contained in:
Alex Kirk committed 2025-12-11 05:49:46 +01:00
1 parent 80ef6832d3
commit 5fb8a25c30
1 file changed
+13 -6
+13 -6
View File
@@ -158,17 +158,24 @@ pub fn strip_ansi(line: &str) -> String {
/// ///
/// This function removes these sequences, keeping only the visible character. /// This function removes these sequences, keeping only the visible character.
pub fn strip_overstrike(line: &str) -> Cow<'_, str> { pub fn strip_overstrike(line: &str) -> Cow<'_, str> {
if !line.contains('\x08') { let Some(first_bs) = line.find('\x08') else {
return Cow::Borrowed(line); return Cow::Borrowed(line);
} };
let mut output = String::with_capacity(line.len()); let mut output = String::with_capacity(line.len());
output.push_str(&line[..first_bs]);
for c in line.chars() {
if c == '\x08' {
output.pop(); output.pop();
let mut remaining = &line[first_bs + 1..];
loop {
if let Some(bs_pos) = remaining.find('\x08') {
output.push_str(&remaining[..bs_pos]);
output.pop();
remaining = &remaining[bs_pos + 1..];
} else { } else {
output.push(c); output.push_str(remaining);
break;
} }
} }