Repository navigation
Convert long runs of letters with no uppercase form in linear time [patch] - #139
Merged
Merged
Conversation
IsWordBoundary ran two scans over the surrounding run of lowercase letters with no uppercase form (ß, ĸ, fi, 𝓪) at every code point, whether or not their result was used. On a run of n such letters every converter did O(n²) allocating work: 16,000 "ß" took ~17 s. The forward scan now runs only when an acronym tail is possible, and the backward scan only after the cheap currentIsUpper check. Fixes #138 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW2PeSdxz6omjxYwwT4
|
This was referenced Oct 30, 2026
matt-edmondson
pushed a commit
that referenced
this pull request
Nov 4, 2026
Resolves the conflict in IsWordBoundary with #139 and #143. The inherited uppercase of a letter with no uppercase form is now looked up only before a capital, the same way #139 made the cased-next scan lazy. Looked up at every code point, it walked back over a long run of such letters each time and failed LongRunOfLowercaseWithNoUppercaseConvertsInLinearTime. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5wGJLhri3KXBeZJwH
This was referenced Nov 11, 2026
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.



Fixes #138
What was wrong
IsWordBoundaryran at every code point, and each call ran two scans over the surrounding run of lowercase letters that have no uppercase form (ß,ĸ,fi,𝓪, …), whether or not their result was used:SkipLowercaseWithNoUppercasescan, whose result only the acronym-tail check readsEndsWordThatIsNotUppercasescan, which ran before the cheapcurrentIsUppertestEvery converter was therefore O(n²) on such a run. 16,000
ßtook about 17 s, and pasted "fancy font" text made this a cheap denial of service.Change
Both are the guards the issue suggested, and neither changes which boundaries are found:
casedNextStartonly whenpreviousIsUpper && currentIsUpper, which is the only case where it is read.currentIsUpperbeforeEndsWordThatIsNotUppercase.&&is commutative here because both operands are side-effect free.Tests
LongRunOfLowercaseWithNoUppercaseConvertsInLinearTimehas three rows:ß,ĸand𝓪×16,000. Each row runs all six converters on the run by itself and again after an all-caps run ("A"×16000 + run + "a"), which keeps the acronym path exercised. Each conversion must finish within 2 s.net10.0: 213/213 pass, including"STRAßE"and"XMLÉtude".Making
IsLowercaseWithNoUppercaseallocation-free is left as the follow-up the triage suggested.Generated by Claude Code