Skip to content

perf: replace lookbehind regex in _normalizeLineEndings with string replaceAll - #303

Merged
robert-virkus merged 1 commit into
Enough-Software:mainfrom
nogringo:fix/normalize-line-endings-performance
Oct 18, 2026
Merged

robert-virkus merged 1 commit into
Enough-Software:mainfrom
nogringo:fix/normalize-line-endings-performance

Conversation

@nogringo

Copy link
Copy Markdown
Contributor

TextMimeData._normalizeLineEndings() converts bare LF to CRLF with a lookbehind regex, (?<!\r)\n. This replaces it with two plain string replacements: collapse every CRLF to LF, then expand every LF to CRLF.

The output is identical, including edge cases such as \r\r\n, lone \r and empty input. It is about 8x faster on typical text:

Input Regex replaceAll
100 KB 2.59 ms 0.34 ms
1 MB 24.55 ms 2.68 ms
5 MB 116.15 ms 14.18 ms

@robert-virkus

Copy link
Copy Markdown
Member

Nice one 👍

@robert-virkus
robert-virkus merged commit c89a141 into Enough-Software:main Oct 18, 2026
1 check passed
@nogringo

Copy link
Copy Markdown
Contributor Author

Thank you. When do you plan to release a new version on pub.dev ? We are waiting it #277 #286

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.

2 participants