Repository navigation
Scan for line breaks in a single pass in SpanLineEnumerator - #682
Merged
Merged
Conversation
This was referenced Oct 12, 2026
This was referenced Oct 14, 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.
SpanLineEnumerator.MoveNext(theEnumerateLinespolyfill, active below net6) searched for the next line break withremaining.IndexOfAny(newlines)over six values. On runtimes where the spanIndexOfAny(values)is not vectorized (theSystem.Memorypackage on .NET Framework / netstandard2.0) that call scans the whole remainder once per value and keeps the lowest hit.\nis the last value in the list, so on LF-only text everyMoveNextrescanned the rest of the input for the five values that never occur, making enumeration quadratic.This replaces the call with a single forward pass that tests each char against
\n,\r,\f,U+0085,U+2028andU+2029. The set of recognised line breaks,\r\nhandling and the trailing-empty-line behaviour are unchanged.Measurements
net48, Release, x64, best of 3, enumerating 8,000 lines of ~30 chars:
Tests
New
PolyfillTests_SpanLineEnumerator.cs(runs against the polyfill below net6 and the BCL from net6):\r\nas one break,\n\ras two, leading/trailing/consecutive breaks, the empty string, and neighbouring chars that must not split (\v,\t,U+0084,U+0086,U+2027,U+202A)MoveNextkeeps returning false after the end