summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-10-09 15:15:47 +0200
committerLaurenz <laurmaedje@gmail.com>2023-10-09 15:15:47 +0200
commitdf49d3f0c6ea17e9dcf552106f7b5464bc99c4dc (patch)
tree030b8716db2cbb07309f706c93c2408819be039b
parent2a19e7f4dcdc5f09da5961f5c9bee4ec955c95c0 (diff)
Optimize `Str::rev`
-rw-r--r--crates/typst/src/eval/str.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/crates/typst/src/eval/str.rs b/crates/typst/src/eval/str.rs
index e7df00e1..666c3c72 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::<String>().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()
}
}