mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-10 08:27:04 +00:00
fixMissingSpaces runs on the main thread once per rendered note. The scan introduced in the previous commit re-tested every detected URL at every character position (and allocated an iterator per position via firstOrNull), i.e. O(N*U*L) for a note with U URLs — noticeable on large notes that carry many links. Bucket the URLs by their first character once up front and only attempt a match at positions whose character can actually start a URL; every other character now costs a single map lookup, keeping the pass linear in the text length for typical content. Buckets stay longest-first so prefix URLs still don't shadow longer ones, so the output is identical (verified against the commons richtext JVM corpus).