FixContinuationStyle: sanitize each paragraph once instead of twice - #14017
Merged
Conversation
The rule walks paragraph pairs and called ContinuationUtilities.SanitizeString on both p and pNext every iteration, so every paragraph was sanitized twice: once as pNext's text, then again as p's text one iteration later. SanitizeString runs four regex replaces per call. Carry the sanitized "next" value forward instead. The carry is captured before the Arabic conversion (which the next iteration reapplies) and dropped whenever the loop writes pNext.Text, so the following iteration re-sanitizes what the paragraph actually holds. Over a 1500-cue file: SanitizeString calls 3462 -> 1964 (-43%), and the rule goes 0.926 ms -> 0.654 ms (-29%). On a continuation-heavy 1200-cue file, where more paragraphs get rewritten and drop the carry, 2.274 ms -> 2.111 ms (-7%). Verified output-identical across 192 configurations (2 corpora x 12 continuation styles x 4 languages x 2 lyrics settings), comparing every paragraph text and every callback log entry - 85,116 recorded fix events, identical checksums. A further 2.4M randomized rule invocations comparing carry against no-carry found no divergence. Adds tests: FixContinuationStyleTest pins a case that actually discriminates a correct carry from a wrong one (a plain continuation chain does not - it passes either way), and UtilitiesCountTagInTextTest covers Utilities.CountTagInText, which had no direct tests despite having two implementations to keep in step. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Summary
FixContinuationStyle.Fixwalks paragraph pairs and calledContinuationUtilities.SanitizeStringon bothpandpNextevery iteration — so every paragraph was sanitized twice: once aspNext's text, then again asp's text one iteration later.SanitizeStringruns four regex replaces per call, and it is the single largest cost in this rule.This carries the sanitized "next" value forward instead. Two details make it exact:
pNext.Text, so the following iteration re-sanitizes what the paragraph actually holds.Benchmark
Apple M4, .NET 10.0.7, Release, best-of-3 with a 300-pass warmup,
new Subtitle(...)copy cost subtracted.SanitizeStringcalls over the 1500-cue file: 3462 → 1964 (−43%).The continuation-heavy corpus gains less precisely because more paragraphs get rewritten, which drops the carry — the safety path doing its job.
Correctness
AllowFix/AddFixToListView/UpdateFixStatus). 85,116 recorded fix events, identical checksums.LibSETests: 1425/1425 pass.LibSE.csprojbuilds clean for bothnetstandard2.1andnet10.0.Note: the
carriedText = nullinvalidation never actually changed output in those 2.4M combinations — the predicates consuming the sanitized text are prefix-insensitive by design. It is kept so the equivalence is structural rather than dependent on that property continuing to hold.Tests
FixContinuationStyleTest— pins a case that genuinely discriminates a correct carry from a wrong one. Worth noting: a plain continuation chain does not — it passes even with a deliberately broken carry, so that version was discarded in favour of one found by brute-force search. Mutation-checked: swappingtextNextfortextin the carry makes it fail.UtilitiesCountTagInTextTest—Utilities.CountTagInTexthad no direct tests, despite the char overload being about to have two implementations to keep in step (Utilities: vectorize CountTagInText(string, char) on .NET 8+ #13991). Covers empty, no-match, adjacent hits, and a hit on the final index (where thenetstandard2.1loop returns early from inside its body), plus agreement between the char and string overloads. Deliberately does not pin null behaviour, which differs by target framework.🤖 Generated with Claude Code