Skip to content

fix(bidi): skip past each run of European terminators in rule W5 - #311

Merged
benoitkugler merged 1 commit into
go-text:mainfrom
gulien:bidi-w5-linear
Nov 20, 2026
Merged

benoitkugler merged 1 commit into
go-text:mainfrom
gulien:bidi-w5-linear

Conversation

@gulien

@gulien gulien commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #307.

Rule W5 walked s.types with a range loop, so after handling a run of ET it went on to the next index of the same run. A run that stays ET was scanned again from each of its characters: about n²/2 steps for n terminators.

The loop now walks by index and jumps to the end of the run once it is handled. The output does not change: the skipped positions either became EN, or stay ET, and then each later start in the run would see an ET before it and the same type after it, and change nothing.

BenchmarkPathological gains a terminators case (# repeated). On darwin/arm64:

Runes Before After
20,000 49 ms 0.6 ms
40,000 191 ms 1.1 ms

The bidi tests pass.

🤖 Generated with Claude Code

@benoitkugler benoitkugler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks !

@benoitkugler
benoitkugler merged commit 79cc91b into go-text:main Nov 20, 2026
7 checks passed
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.

bidi: Rule W5 is quadratic on a run of European terminators

2 participants