Skip to content

Commit

Permalink
Rollup merge of #136662 - thaliaarchi:formatter-pad-char-count, r=m-o…
Browse files Browse the repository at this point in the history
…u-se

Count char width at most once in `Formatter::pad`

When both width and precision flags are specified, then `Formatter::pad` counts the character width twice. Instead, record the character width when truncating it to the precision, so it does not need to be recomputed. Simplify control flow so the cases are more clear.

Related:
- 6c9e708f4be (`fmt::Formatter::pad`: don't call chars().count() more than one time, 2021-09-01): Reduce counting chars from thrice to twice in worst case
- ede39aeb331 (feat: reinterpret `precision` field for strings, 2016-06-29): Change meaning of precision for strings
- b820748ff5a (Implement formatting arguments for strings and integers, 2013-08-10): Implement `Formatter::pad`
  • Loading branch information
jieyouxu authored Mar 5, 2025
2 parents b15d5f4 + 3f20252 commit 34e8f4b
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit 34e8f4b

Please sign in to comment.