KEMBAR78
Avoid redundant work when processing UTF-8 strings by localspook · Pull Request #4475 · fmtlib/fmt · GitHub
Skip to content

Conversation

@localspook
Copy link
Contributor

convert_precision_to_size calculates how many bytes of a UTF-8 string we can print before we exceed a display width limit, but does it using a weird two-step:

  1. Walk the string, calculating the number of code points we can print, and throw away the position we stopped at.
  2. Walk the string again to convert the number of code points into a number of bytes (i.e. recalculate the position we stopped at).

Put like that, the fix is clear. Also, this is the only place code_point_index, the function that does step 2, is used, so we delete it.

@vitaut vitaut merged commit 067bc47 into fmtlib:master Jun 20, 2025
45 checks passed
@vitaut
Copy link
Contributor

vitaut commented Jun 20, 2025

Nice improvement, thanks!

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

Successfully merging this pull request may close these issues.

2 participants