unicode-org / icu4x

Solving i18n for client-side and resource-constrained environments.
https://icu4x.unicode.org
Other
1.38k stars 176 forks source link

Ensure CodePointTrie access by u16 or char omits unnecessary range checks #5819

Open hsivonen opened 4 days ago

hsivonen commented 4 days ago

When CodePointTrie of the fast type is queried with u16, the code point cannot be above FAST_TYPE_FAST_INDEXING_MAX. When CodePointTrie (of either type) is queried with char, the code point cannot be above CODE_POINT_MAX.

We should ensure that the relevant branches are omitted in these cases. Perhaps its good enough to ensure this by Godbolting, but actually having separate code for these cases would be robust (not relying on the optimizer reaching a particular conclusion) and obvious.

hsivonen commented 3 days ago

Godbolting suggests that this optimizes the right way already. (Used trivial examples, not the actual CodePointTrie code.)