quil-rs
quil-rs copied to clipboard
Reduce unnecessary allocations by fmt::Display
Suggesting this because, while it doesn't necessarily look as nice, it should avoid (some of) the unnecessary allocations from building a `Vec<String>` for printing purposes.
write!(f, "{}", self.name)?;
if !key_value_pairs.is_empty() {
write!(f, "(")?;
for (i, (k, v)) in key_value_pairs.iter().enumerate() {
if i > 0 { write!(f, ", ")? }
write!(f, "{}: {}", k, v)?;
}
write!(f, ")")?;
}
Ok(())
}
}
Originally posted by @Shadow53 in https://github.com/rigetti/quil-rs/pull/138#discussion_r1041634062