refactor: replace repeated string allocation

on each iteration with one `String` creation in
`fold`, for efficiency
This commit is contained in:
Hamir Mahal 2024-03-11 00:26:24 -07:00 committed by David Peter
parent 09c39d8989
commit 6c774103d9

View File

@ -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::<String>();
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()