1
0
mirror of https://github.com/sharkdp/bat.git synced 2026-02-08 00:32:08 +00:00

Performance optimization

This commit is contained in:
Alex Kirk
2025-12-09 05:50:52 +01:00
parent 80ef6832d3
commit 5fb8a25c30

View File

@@ -158,17 +158,24 @@ pub fn strip_ansi(line: &str) -> String {
///
/// This function removes these sequences, keeping only the visible character.
pub fn strip_overstrike(line: &str) -> Cow<'_, str> {
if !line.contains('\x08') {
let Some(first_bs) = line.find('\x08') else {
return Cow::Borrowed(line);
}
};
let mut output = String::with_capacity(line.len());
for c in line.chars() {
if c == '\x08' {
output.push_str(&line[..first_bs]);
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 {
output.push(c);
output.push_str(remaining);
break;
}
}