From 0a52e4321f808f57a91174a98daeab84e7f7de2a Mon Sep 17 00:00:00 2001 From: curious-rabbit Date: Wed, 1 Jul 2026 07:54:51 +0200 Subject: [PATCH] improve patch --- src/preprocessor.rs | 8 +++----- src/pretty_printer.rs | 7 ++----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/preprocessor.rs b/src/preprocessor.rs index b8e326c7..971ae3d4 100644 --- a/src/preprocessor.rs +++ b/src/preprocessor.rs @@ -155,11 +155,9 @@ pub fn sanitize(line: &str) -> String { let bytes = stripped.as_bytes(); let mut start = 0; let mut i = 0; - while i < bytes.len() { - if !is_sanitize_trigger(bytes[i]) { - i += 1; - continue; - } + // Skip directly to the next trigger byte instead of testing each one. + while let Some(off) = bytes[i..].iter().position(|&b| is_sanitize_trigger(b)) { + i += off; let len = sanitize_at(bytes, i, &stripped, &mut buffer, &mut start); i += len; } diff --git a/src/pretty_printer.rs b/src/pretty_printer.rs index 582e972b..1dc510f4 100644 --- a/src/pretty_printer.rs +++ b/src/pretty_printer.rs @@ -194,13 +194,10 @@ impl<'a> PrettyPrinter<'a> { /// Whether to sanitize untrusted input for safe display (default: never) /// - /// Implies [`strip_ansi`](Self::strip_ansi) at the same value, and also - /// replaces terminal-active and bidi / zero-width bytes with U+FFFD. + /// Strips ANSI escape sequences and additionally substitutes terminal-active + /// control bytes and bidi / zero-width codepoints with U+FFFD. pub fn sanitize(&mut self, mode: StripAnsiMode) -> &mut Self { self.config.sanitize = mode; - if mode != StripAnsiMode::Never { - self.config.strip_ansi = mode; - } self }