From fbbbccf61c62366d38297a8228ebceae9dce8dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Romero?= Date: Wed, 30 Sep 2026 18:37:04 +0000 Subject: [PATCH] perf: reserve escaped calendar values precisely --- crates/flectar-mail-core/src/calendar/mod.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/flectar-mail-core/src/calendar/mod.rs b/crates/flectar-mail-core/src/calendar/mod.rs index d8a0e3fe..8235d56d 100644 --- a/crates/flectar-mail-core/src/calendar/mod.rs +++ b/crates/flectar-mail-core/src/calendar/mod.rs @@ -515,7 +515,15 @@ pub fn parse_ics(text: &str) -> Vec { } pub(crate) fn escape(v: &str) -> String { - let mut out = String::with_capacity(v.len()); + let capacity = v + .chars() + .map(|character| match character { + '\\' | ',' | ';' | '\n' => 2, + '\r' => 0, + _ => character.len_utf8(), + }) + .sum(); + let mut out = String::with_capacity(capacity); for c in v.chars() { match c { '\\' => out.push_str("\\\\"),