replace InCB_Extend_table search with simple predicates - #178
Merged
Conversation
According to [UCD](https://www.unicode.org/reports/tr44/), the property `InCB=Extend` is defined as: ``` \p{InCB = Extend} ≔ [ \p{gcb=Extend} \p{gcb=ZWJ} - \p{InCB=Linker} - \p{InCB=Consonant} - [\u200C] ] ``` And no `InCB=Consonant` is `gcb=Extend` or `gcb=ZWJ`. So in can be determined with the grapheme category the caller already has and two equality. `scripts/unicode.py` now checks that derivation against the UCD. A future Unicode version that breaks either fact fails the generator instead of silently mis-segmenting Indic text. Also one fact that is `InCB=Linker` and `InCB=Extend` are subset of `gcb=Extend`, any other category rules out both without inspecting the codepoint. This change improves the overall performance of the grapheme APIs by skipping unnecessary category checks and table searches in the hot loop. On my machine, it measures approximately -15 to -20%.
Manishearth
approved these changes
Jul 31, 2026
Manishearth
left a comment
Member
There was a problem hiding this comment.
Great, thanks! These properties do change often, but the python code's preemptive check is good and also pretty clear about how to change things.
Contributor
Author
|
Thanks for the review! next up will be also similar approach and size. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context: #177
(I wrote it without using the strategy of folding
InCB=Consonantinto the cats enum to make changes small and isolated)According to UCD, the property
InCB=Extendis defined as:And no
InCB=Consonantisgcb=Extendorgcb=ZWJ. So in can be determined with the grapheme category the caller already has and two equality.scripts/unicode.pynow checks that derivation against the UCD. A future Unicode version that breaks either fact fails the generator instead of silently mis-segmenting Indic text.Also one fact that is
InCB=LinkerandInCB=Extendare subset ofgcb=Extend, any other category rules out both without inspecting the codepoint.This change improves the overall performance of the grapheme APIs by skipping unnecessary category checks and table searches in the hot loop. On my machine, it measures approximately -15 to -20%.