Skip to content

Commit 1cecd06

Browse files
avargitster
authored andcommitted
generate-cmdlist.sh: don't parse command-list.txt thrice
Change the "define_categories()" and "define_category_names()" functions to take the already-parsed output of "category_list()" as an argument, which brings our number of passes over "command-list.txt" from three to two. Then have "category_list()" itself take the output of "command_list()" as an argument, bringing the number of times we parse the file to one. Compared to the pre-image this speeds us up quite a bit: $ git show HEAD~:generate-cmdlist.sh >generate-cmdlist.sh.old $ hyperfine --warmup 10 -L v ,.old 'sh generate-cmdlist.sh{v} command-list.txt' Benchmark #1: sh generate-cmdlist.sh command-list.txt Time (mean ± σ): 22.9 ms ± 0.3 ms [User: 15.8 ms, System: 9.6 ms] Range (min … max): 22.5 ms … 24.0 ms 125 runs Benchmark #2: sh generate-cmdlist.sh.old command-list.txt Time (mean ± σ): 30.1 ms ± 0.4 ms [User: 24.4 ms, System: 17.5 ms] Range (min … max): 29.5 ms … 32.3 ms 96 runs Summary 'sh generate-cmdlist.sh command-list.txt' ran 1.32 ± 0.02 times faster than 'sh generate-cmdlist.sh.old command-list.txt' Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent e88842e commit 1cecd06

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

generate-cmdlist.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ command_list () {
2626
}
2727

2828
category_list () {
29-
command_list "$1" |
29+
echo "$1" |
3030
cut -d' ' -f2- |
3131
tr ' ' '\012' |
3232
grep -v '^$' |
@@ -37,7 +37,7 @@ define_categories () {
3737
echo
3838
echo "/* Command categories */"
3939
bit=0
40-
category_list "$1" |
40+
echo "$1" |
4141
while read cat
4242
do
4343
echo "#define CAT_$cat (1UL << $bit)"
@@ -51,7 +51,7 @@ define_category_names () {
5151
echo "/* Category names */"
5252
echo "static const char *category_names[] = {"
5353
bit=0
54-
category_list "$1" |
54+
echo "$1" |
5555
while read cat
5656
do
5757
echo " \"$cat\", /* (1UL << $bit) */"
@@ -64,7 +64,7 @@ define_category_names () {
6464
print_command_list () {
6565
echo "static struct cmdname_help command_list[] = {"
6666

67-
command_list "$1" |
67+
echo "$1" |
6868
while read cmd rest
6969
do
7070
synopsis=
@@ -93,15 +93,18 @@ do
9393
shift
9494
done
9595

96+
commands="$(command_list "$1")"
97+
categories="$(category_list "$commands")"
98+
9699
echo "/* Automatically generated by generate-cmdlist.sh */
97100
struct cmdname_help {
98101
const char *name;
99102
const char *help;
100103
uint32_t category;
101104
};
102105
"
103-
define_categories "$1"
106+
define_categories "$categories"
104107
echo
105-
define_category_names "$1"
108+
define_category_names "$categories"
106109
echo
107-
print_command_list "$1"
110+
print_command_list "$commands"

0 commit comments

Comments
 (0)