Repository navigation
Simplify and optimize utf8.c - #136915
Simplify and optimize utf8.c#136915
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @dotnet/runtime-infrastructure |
|
This is a drop-in replacement for the existing API, and well-formed input converts exactly as before, as does ill-formed input mid-string (same U+FFFD replacement as main). It does change four edge cases where main misbehaved:
After this (and #136821), I intend to rewrite unicode related PAL tests somewhere under src/tests, before deleting PAL's unicode.cpp wrapper layer and deleting unicode PAL tests. |
There was a problem hiding this comment.
🟡 Changes recommended
The WideCharToMultiByte tests lack coverage of the new 4096-block accumulation/reset boundary, leaving byte-count errors that could cause undersized buffer allocations unchecked.
1 open issue
What changed in this PR
This PR simplifies minipal’s UTF-8/UTF-16 conversion implementation, reviving #102424 with additional fast paths for length calculation and conversion.
Changes:
- Replaces stateful fallback machinery with focused decoding and encoding helpers.
- Adds word-sized ASCII processing and specialized loops for multibyte sequences and surrogate pairs.
- Centralizes malformed-input handling, byte swapping, and destination-capacity checks.
| File | Description |
|---|---|
src/native/minipal/utf8.c |
Rewrites UTF conversion and length-calculation routines with simpler helpers and optimized fast paths. |
Review effort: Balanced
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
|
/azp run runtime-coreclr outerloop |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/ba-g known failures |

Reviving #102424 with optimizations.