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

Re: [PATCH] pack-objects: use strcspn(3) in name_cmp_len()

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Feb 5, 2023, 20:59 UTC
Message-ID
<230205.86357j95wj.gmgdl@evledraar.gmail.com>
In-Reply-To
<7315487c-c97c-b8a2-d3b2-4fbf642495dd@web.de>
On Sun, Feb 05 2023, René Scharfe wrote:
Show 9 quoted lines
> -static int name_cmp_len(const char *name)
> +static size_t name_cmp_len(const char *name)
>  {
> -	int i;
> -	for (i = 0; name[i] && name[i] != '\n' && name[i] != '/'; i++)
> -		;
> -	return i;
> +	return strcspn(name, "\n/");
>  }

I wonder if this name_cmp_len() is worth keeping at all. If all we're doing is wrapping strcspn() (which b.t.w, seem to be less "open-coding" and just that it wasn't known to the original author in 5d4a6003354 (Make git-pack-objects a builtin, 2006-08-03)), then just inlining that in the two name_cmp_len() invocations would be better, or maybe:

	strcspn(..., object_reject);

Where we previously declared "object_reject" (or same better name for such a variable) to be "\n/".

Show 14 quoted lines
>  static void add_pbase_object(struct tree_desc *tree,
>  			     const char *name,
> -			     int cmplen,
> +			     size_t cmplen,
>  			     const char *fullname)
>  {
>  	struct name_entry entry;
>  	int cmp;
>
>  	while (tree_entry(tree,&entry)) {
>  		if (S_ISGITLINK(entry.mode))
>  			continue;
>  		cmp = tree_entry_len(&entry) != cmplen ? 1 :
>  		      memcmp(name, entry.path, cmplen);

The return of tree_entry_len() is "int", so that's a new implicit cast, but that seems OK in this case (and the "namelen" is another thing we should convert to "size_t").

Previous: René ScharfeNext: Junio C Hamano
Message 2 of 3 in “pack-objects: use strcspn(3) in name_cmp_len()”
  1. pack-objects: use strcspn(3) in name_cmp_len()René Scharfe, Feb 5, 2023
  2. Ævar Arnfjörð BjarmasonFeb 5, 2023
  3. Junio C HamanoFeb 6, 2023

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.