From c59915d024f1baf73e109abda96a8234eb1b0f77 Mon Sep 17 00:00:00 2001 From: Hamir Mahal Date: Mon, 11 Mar 2024 00:26:24 -0700 Subject: [PATCH] refactor: replace repeated string allocation on each iteration with one `String` creation in `fold`, for efficiency --- src/command.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/command.rs b/src/command.rs index ddb9fe052..55cbb5e74 100644 --- a/src/command.rs +++ b/src/command.rs @@ -59,10 +59,11 @@ impl<'a> Command<'a> { } pub fn get_name_with_unused_parameters(&self) -> String { - let parameters = self - .get_unused_parameters() - .map(|(parameter, value)| format!("{} = {}, ", parameter, value.to_string())) - .collect::(); + let parameters = + self.get_unused_parameters() + .fold(String::new(), |output, (parameter, value)| { + output + &format!("{} = {}, ", parameter, value.to_string()) + }); let parameters = parameters.trim_end_matches(", "); let parameters = if parameters.is_empty() { "".into()