quil-rs icon indicating copy to clipboard operation
quil-rs copied to clipboard

Reduce unnecessary allocations by fmt::Display

Open randall-fulton opened this issue 2 years ago • 0 comments

    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

randall-fulton avatar Dec 07 '22 13:12 randall-fulton