Commit 84c5d92
Fix O(n^2) parsing time with --fspoilers and deeply nested brackets
The spoiler analysis loop in md_analyze_link_contents() was called
recursively for every resolved link pair (by md_resolve_links()), but
lacked the skip-resolved-spans optimization present in md_analyze_marks().
With deeply nested bracket structures (e.g. the OSS-Fuzz testcase
clusterfuzz-testcase-fuzz-mdhtml-5579634954797056 with 37,034 nesting
levels), the loop iterated O(n^2) over the same marks, causing 13+
second parse times for a 661 kB input.
Fix: when the loop encounters a resolved link or image opener ('[', '!'),
jump directly to mark->next (the closer) instead of walking through
every mark inside the span one by one. This mirrors the skip logic in
md_analyze_marks() and reduces total iterations from O(n^2) to O(n).
Closes #311.
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent 347b528 commit 84c5d92
1 file changed
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4173 | 4173 | | |
4174 | 4174 | | |
4175 | 4175 | | |
4176 | | - | |
| 4176 | + | |
| 4177 | + | |
| 4178 | + | |
| 4179 | + | |
| 4180 | + | |
| 4181 | + | |
| 4182 | + | |
4177 | 4183 | | |
| 4184 | + | |
4178 | 4185 | | |
4179 | 4186 | | |
4180 | 4187 | | |
| |||
0 commit comments