perf: reserve escaped calendar values precisely

This commit is contained in:
Tomás Romero committed 2026-09-30 22:11:28 +00:00
1 parent bb79e29575
commit fbbbccf61c
1 file changed
+9 -1
+9 -1
View File
@@ -515,7 +515,15 @@ pub fn parse_ics(text: &str) -> Vec<IcsEvent> {
}
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("\\\\"),