fortran-lang / fprettify

auto-formatter for modern fortran source code
https://pypi.python.org/pypi/fprettify
Other
370 stars 76 forks source link

Slow greedy regex #112

Open danielhollas opened 3 years ago

danielhollas commented 3 years ago

Greedily matching numbers in F90_CONSTANTS_TYPES_RE is super slow for numbers with many digits.

https://github.com/pseewald/fprettify/blob/cb254022c2034ad3b8f744f4dad1bf5b7438815d/fprettify/__init__.py#L475

Kudos to @Jellby and @zaikunzhang for independently discovering this and fixing it as part of their PRs in https://github.com/pseewald/fprettify/pull/99/commits/2f766f33ed795ee69d0ac404e699e5475ff52f3f and https://github.com/pseewald/fprettify/pull/106/commits/bf41457c782997e378144297e764092d09a3fa5f, respectively.

Since those PRs are not yet merged, I am documenting the issue here for clarity. As one data point, parsing one file with 600 lines containing a lot of numbers went from 12s to 1s after the fix!