Skip to content

Conversation

eeemmmmmm
Copy link

@eeemmmmmm eeemmmmmm commented Sep 9, 2025

Motivation

Replace inefficient format!("{}", value) pattern with direct to_string() method call for simple numeric-to-string conversions. The format! macro has overhead from the formatting machinery that is unnecessary when converting a single value to string.

Solution

Changed Ok(format!("{}", code.len())) to Ok(code.len().to_string()) in the codesize method. This micro-optimization improves performance by avoiding the format string parsing and reduces memory allocations while maintaining identical behavior.

PR Checklist

  • Added Tests - N/A (identical behavior, no functional changes)
  • Added Documentation - N/A (no API changes)
  • Breaking changes - No

DaniPopes added a commit that referenced this pull request Sep 9, 2025
This PR aggregates changes from the following PRs:

- Closes #11572 by @\Forostovec
- Closes #11589 by @\sashass1315
- Closes #11592 by @\sashaodessa
- Closes #11595 by @\eeemmmmmm
@DaniPopes DaniPopes mentioned this pull request Sep 9, 2025
@zugdev
Copy link
Contributor

zugdev commented Sep 10, 2025

is this still true?

rust-lang/rust#99012

@DaniPopes
Copy link
Member

sometimes, when ToString is specialized for the type. i prefer to_string regardless because i think its intent is clearer.

@grandizzy grandizzy closed this in f182a95 Sep 10, 2025
@github-project-automation github-project-automation bot moved this to Done in Foundry Sep 10, 2025
MerkleBoy pushed a commit to MerkleBoy/foundry that referenced this pull request Sep 17, 2025
This PR aggregates changes from the following PRs:

- Closes foundry-rs#11572 by @\Forostovec
- Closes foundry-rs#11589 by @\sashass1315
- Closes foundry-rs#11592 by @\sashaodessa
- Closes foundry-rs#11595 by @\eeemmmmmm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants