fprettify
fprettify copied to clipboard
Closes #112 Slow greedy regex
When applying fprettify using the --case 1 1 1 1 option, the following code takes a long time to format because of the matching of floating point constants:
program main
implicit none
real, dimension(2) :: array
array = [9.23529879234512349823d-02, 3.34099894387578238101e-01]
print *, sum(array)
end program main
On my computer, it takes 6.5 seconds to format. With my simplification of F90_NUMBER_ALL_RE, it still takes 3.2 seconds to format. Finally applying the fix from https://github.com/fortran-lang/fprettify/issues/112, it only takes 0.13 seconds to format.
A part of this PR is already adressed in https://github.com/fortran-lang/fprettify/pull/99, but it appears to be stalled, and I hope that this small fix is easier to review. I noticed the issue because formatting some files at work took > 5 minutes, and a profiler showed that 99% of the time was spent matching these regexes. Apparently this was also noticed by @Jellby and @zaikunzhang in the past, see issue.