diff --git a/crates/typst/src/eval/str.rs b/crates/typst/src/eval/str.rs index e7df00e1a..666c3c723 100644 --- a/crates/typst/src/eval/str.rs +++ b/crates/typst/src/eval/str.rs @@ -591,7 +591,11 @@ impl Str { /// Reverse the string. #[func(title = "Reverse")] pub fn rev(&self) -> Str { - self.as_str().graphemes(true).rev().collect::().into() + let mut s = EcoString::with_capacity(self.0.len()); + for grapheme in self.as_str().graphemes(true).rev() { + s.push_str(grapheme); + } + s.into() } }