Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce unnecessary allocations by fmt::Display #139

Open
randall-fulton opened this issue Dec 7, 2022 · 0 comments
Open

Reduce unnecessary allocations by fmt::Display #139

randall-fulton opened this issue Dec 7, 2022 · 0 comments

Comments

@randall-fulton
Copy link
Contributor

    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 #138 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant