[PR #10966] Refactor u8u16 and u16u8 conversion functions #28332

Open
opened 2026-01-31 09:27:50 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/10966

State: closed
Merged: Yes


  • Perform the handling of partial code points in the u8u16 and u16u8
    conversion functions without preparation in a preliminary buffer.
  • Simplify partials handling in u8u16 (perf).
  • Declare the parameters for the incoming data as referenced
    string_views.
  • Simplify templatization.
  • Simplify exception handling.

We complete the partial codepoint in the 4-bytes long cache and convert
it separately. This makes the cache ready for capturing the next
partials before the remaining string is converted. This way, we neither
need to copy the whole string into a buffer which contains complete
codepoints, nor do we need to allocate an unnecessarily long buffer
which exists for the life time of the state class instance.

Finding and capturing of partials is performed in a more linear code
using the evaluation of the length of a code point.

The parameters for the incoming data are now explicitely declared to be
referenced string_views.

CATCH_RETURN is used to improve the readability of the code.

Validation Steps Performed

  • manually tested
  • unit tests passed

Closes #10946

Co-authored-by: Leonard Hecker lhecker@microsoft.com

**Original Pull Request:** https://github.com/microsoft/terminal/pull/10966 **State:** closed **Merged:** Yes --- * Perform the handling of partial code points in the `u8u16` and `u16u8` conversion functions without preparation in a preliminary buffer. * Simplify partials handling in `u8u16` (perf). * Declare the parameters for the incoming data as referenced string_views. * Simplify templatization. * Simplify exception handling. We complete the partial codepoint in the 4-bytes long cache and convert it separately. This makes the cache ready for capturing the next partials before the remaining string is converted. This way, we neither need to copy the whole string into a buffer which contains complete codepoints, nor do we need to allocate an unnecessarily long buffer which exists for the life time of the state class instance. Finding and capturing of partials is performed in a more linear code using the evaluation of the length of a code point. The parameters for the incoming data are now explicitely declared to be referenced string_views. `CATCH_RETURN` is used to improve the readability of the code. ## Validation Steps Performed * manually tested * unit tests passed Closes #10946 Co-authored-by: Leonard Hecker <lhecker@microsoft.com>
claunia added the pull-request label 2026-01-31 09:27:50 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#28332