cmdline-opts/gen.pl: improve performance

On some systems, the gen.pl script takes nearly two minutes for the
generation of the main-page, which is a completely unacceptable time.

The slow performance has two causes:
1. Use of a regex locale operator
2. Useless invokations of loops

The commit addresses the first issue by replacing the "\W" wiht
[^a-zA-Z0-9_], which is, according to regex101.com, functionally
equivalent to the previous operation, except that it is obviously
limited to ASCII only, which is fine, as the curl project is
English-only anyway.

The second issue is being addressed by only running the loop if the line
contains a "--" in it. The loop may be completeley removed in the
future.

Co-authored-by: Emanuele Torre <torreemanuele6@gmail.com>

See #8299
Fixes #9230
Closes #9232
This commit is contained in:
Emil Engler 2022-07-30 22:36:55 +02:00 committed by Daniel Stenberg
parent 209ffd7d8e
commit 92179353e5

View File

@ -103,10 +103,10 @@ sub printdesc {
print ".fi\n"; # fill-in
}
# skip lines starting with space (examples)
if($d =~ /^[^ ]/) {
if($d =~ /^[^ ]/ && $d =~ /--/) {
for my $k (keys %optlong) {
my $l = manpageify($k);
$d =~ s/--$k([^a-z0-9_-])(\W)/$l$1$2/;
$d =~ s/--\Q$k\E([^a-z0-9_-])([^a-zA-Z0-9_])/$l$1$2/;
}
}
# quote "bare" minuses in the output