git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] builtins: search builtin commands via binary search.

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jul 26, 2013, 20:57 UTC
Message-ID
<20130726205737.GI14690@google.com>
In-Reply-To
<1374871850-24323-1-git-send-email-stefanbeller@googlemail.com>
Hi,
Stefan Beller wrote:
Show 9 quoted lines
> --- a/git.c
> +++ b/git.c
> @@ -309,9 +309,18 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
>  	return 0;
>  }
>  
> +static int compare_internal_command(const void *a, const void *b) {
> +	/* The first parameter is of type char* describing the name,
> +	   the second is a struct cmd_struct */
Style:
	/*
	 * Multi-line comments in git look like this, with an initial
	 * "/*" line, a leading "*" on each line with text, and a line
	 * with '*' '/' at the end.
	 */
[...]
Show 11 quoted lines
> @@ -447,12 +456,12 @@ static void handle_internal_command(int argc, const char **argv)
>  		argv[0] = cmd = "help";
>  	}
>  
> -	for (i = 0; i < ARRAY_SIZE(commands); i++) {
> -		struct cmd_struct *p = commands+i;
> -		if (strcmp(p->cmd, cmd))
> -			continue;
> +	struct cmd_struct *p = (struct cmd_struct *)bsearch(cmd, commands,
> +				ARRAY_SIZE(commands), sizeof(struct cmd_struct),
> +				compare_internal_command);
No need to cast --- this is C.

Fun. Does this result in a measurable speedup, or is it just for more pleasant reading?

Thanks and hope that helps, Jonathan

Previous: Stefan BellerNext: Stefan Beller
Message 2 of 8 in “builtins: search builtin commands via binary search.”
  1. builtins: search builtin commands via binary search.Stefan Beller, Jul 26, 2013
  2. Jonathan NiederJul 26, 2013
  3. Stefan BellerJul 27, 2013
  4. builtins: search builtin commands via binary search.Stefan Beller, Jul 27, 2013
  5. Andreas SchwabJul 27, 2013
  6. Eric SunshineJul 28, 2013
  7. Junio C HamanoJul 29, 2013
  8. Eric SunshineJul 27, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.