]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmdline-opts/gen.pl: improve performance
authorEmil Engler <me@emilengler.com>
Sat, 30 Jul 2022 20:36:55 +0000 (22:36 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 2 Aug 2022 15:10:03 +0000 (17:10 +0200)
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

docs/cmdline-opts/gen.pl

index e69dd996bfc4a8c2aaf2a2a84304e7546383da4d..cbe4540625a3c1f52130fd5adfb8f772abb4783e 100755 (executable)
@@ -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