commonmark / cmark

CommonMark parsing and rendering library and program in C
Other
1.62k stars 539 forks source link

Quadratic behavior when parsing smart quotes #388

Closed nwellnhof closed 3 years ago

nwellnhof commented 3 years ago

Simply parsing a sequence of single or double quote characters exhibits quadratic behavior when the "smart" option is enabled:

$ for n in 5000 10000 20000; do python3 -c "print(\"'\"*$n)" |time -f "$n chars: %e secs" build/src/cmark --smart >/dev/null; done
5000 chars: 0.15 secs
10000 chars: 0.70 secs
20000 chars: 4.33 secs

This seems to be caused by this loop in process_emphasis.