Call load_command_list() only when it is needed
PATCH 1/2 Call load_command_list() only when it is needed
This avoids list_commands_in_dir() being called when not needed which is quite slow due to file I/O in order to list matching files in a directory.
--- builtin/help.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
builtin/help.c +2 -1
@@ -288,6 +288,7 @@ static struct cmdnames main_cmds, other_cmds;static int is_git_command (const char *s) { +load_command_list ("git-" , &main_cmds, &other_cmds);return is_in_cmdlist (&main_cmds, s) ||is_in_cmdlist (&other_cmds, s); }
@@ -449,7 +450,6 @@ int cmd_help(int argc, const char **argv, const char *prefix)int nongit;const char *alias;enum help_format parsed_help_format; -load_command_list ("git-" , &main_cmds, &other_cmds); argc =parse_options (argc, argv, prefix, builtin_help_options, builtin_help_usage,0 );
@@ -458,6 +458,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)if (show_all) {git_config (git_help_config,NULL );printf (_ ("usage: %s%s" ),_ (git_usage_string),"\n\n" ); +load_command_list ("git-" , &main_cmds, &other_cmds);list_commands (colopts, &main_cmds, &other_cmds); }
Signature · 1 line
1.8.4.msysgit.0
PATCH 2/2 Speed up is_git_command() by checking early for internal commands
Since 2dce956 is_git_command() was a bit slow as it does file I/O in the call to list_commands_in_dir(). Avoid the file I/O by adding an early check for internal commands.
--- builtin/help.c | 5 ++ git.c | 242 ++++++++++++++++++++++++++++++--------------------------- 2 files changed, 132 insertions(+), 115 deletions(-)
builtin/help.c +5 -0
@@ -284,10 +284,15 @@ static int git_help_config(const char *var, const char *value, void *cb)return git_default_config (var, value, cb); } +extern int is_internal_command (const char *s); +static struct cmdnames main_cmds, other_cmds;static int is_git_command (const char *s) { +if (is_internal_command (s)) +return 1 ; +load_command_list ("git-" , &main_cmds, &other_cmds);return is_in_cmdlist (&main_cmds, s) ||is_in_cmdlist (&other_cmds, s);
git.c +127 -115
251 lines not on this page · raw message
Signature · 1 line
1.8.4.msysgit.0
Re: [PATCH 2/2] Speed up is_git_command() by checking early for internal commands
Quoted 15 lines · Sebastian Schuberth
Since 2dce956
is_git_command()was a bit slow as it does file I/O in the call tolist_commands_in_dir(). Avoid the file I/O by adding an early check for internal commands.Signed-off-by Sebastian Schuberth <[email protected]>--- builtin/help.c | 5 ++ git.c | 242 ++++++++++++++++++++++++++++++--------------------------- 2 files changed, 132 insertions(+), 115 deletions(-)builtin/help.c +0
-0
builtin/help.c static int git_help_config(const char *var, const char *value, void *cb) · line 288
Quoted 5 lines
builtin/help.c +2
-0@@ -284,10 +284,15 @@ static int git_help_config(const char *var, const char *value, void *cb)return git_default_config (var, value, cb); } +extern int is_internal_command (const char *s); +
Starting the new year in keeping with the fine tradition of asking people who add stuff to clean up what others left behind, I would suggest moving all the code related to internal commands (or maybe all commands) in a new pair of files like "internal-cmds.{c,h}". This way git.c and builtin/help.c could include internal-cmds.h and you wouldn't need such extern declaration.
Happy new year everyone,
Christian.
Re: [PATCH 2/2] Speed up is_git_command() by checking early for internal commands
Quoted 8 lines · Christian Couder
Quoted 8 lines
builtin/help.c +0
-0@@ -284,10 +284,15 @@ static int git_help_config(const char *var, const char *value, void *cb)return git_default_config (var, value, cb); }
Quoted 9 lines
builtin/help.c static int git_help_config(const char *var, const char *value, void *cb) · line 288
Quoted 2 lines
builtin/help.c +2
-0+extern int is_internal_command (const char *s); +Starting the new year in keeping with the fine tradition of asking people who add stuff to clean up what others left behind, I would suggest moving all the code related to internal commands (or maybe all commands) in a new pair of files like "internal-cmds.{c,h}". This way
git.candbuiltin/help.ccould includeinternal-cmds.hand you wouldn't need such extern declaration.
Wouldn't the existing builtin.h be a more appropriate for this? (And create a builtin.c for the implementations.)
Also, I start to realize that it's a bit unfortunate that we seem to use the terms "builtin" and "internal command" interchangeably. I'll probably add a patch to address this.
Signature · 1 line
Sebastian Schuberth