From 62e352afb149bc3f6e57637c46eabb019b8f7405 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 4 Feb 2024 12:53:20 +0000 Subject: [PATCH] Reduce String consing in reply userid Not sure if this is worthwile. You may want to suppress the lint clippy::format_collect instead. --- src/posting.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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. -- 2.30.2