From: Ian Jackson Date: Sun, 4 Feb 2024 12:53:20 +0000 (+0000) Subject: Reduce String consing in reply userid X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=62e352afb149bc3f6e57637c46eabb019b8f7405;p=mastodonochrome.git Reduce String consing in reply userid Not sure if this is worthwile. You may want to suppress the lint clippy::format_collect instead. --- diff --git a/src/posting.rs b/src/posting.rs index 82ba71b..f6062e3 100644 --- a/src/posting.rs +++ b/src/posting.rs @@ -1,3 +1,4 @@ +use std::fmt::Write as _; use std::iter::once; use sys_locale::get_locale; @@ -103,7 +104,10 @@ impl Post { .chain(st.mentions.iter().map(|m| client.fq(&m.acct))) .filter(|acct| acct != &ourself); - let text = userids.map(|acct| format!("@{} ", acct)).collect(); + let text = userids.fold(String::new(), |mut s, acct| { + write!(s, "@{} ", acct).expect("fmt to string failed"); + s + }); // Set a default content warning of the same as the post we're // replying to.