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

Re: [PATCH/RFC v2 2/2] Replace strlen() with ce_namelen()

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 9, 2012, 02:49 UTC
Message-ID
<7v4nphmyxc.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1341590850-15653-3-git-send-email-t.gummerer@gmail.com>
Thomas Gummerer <t.gummerer@gmail.com> writes:
Show 5 quoted lines
> Replace strlen(ce->name) with ce_namelen() in a couple
> of places which gives us some additional bits of
> performance.
>
> Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Very sensible, with or without the previous patch.

I am kind of surprised that we are very good and have only these three places that had these unnecessary pessimization.

Show 40 quoted lines
> ---
>  read-cache.c   |    4 ++--
>  unpack-trees.c |    2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/read-cache.c b/read-cache.c
> index ea75c89..a77877a 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -1124,7 +1124,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
>  			continue;
>  
>  		if (pathspec &&
> -		    !match_pathspec(pathspec, ce->name, strlen(ce->name), 0, seen))
> +		    !match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen))
>  			filtered = 1;
>  
>  		if (ce_stage(ce)) {
> @@ -1852,7 +1852,7 @@ int read_index_unmerged(struct index_state *istate)
>  		if (!ce_stage(ce))
>  			continue;
>  		unmerged = 1;
> -		len = strlen(ce->name);
> +		len = ce_namelen(ce);
>  		size = cache_entry_size(len);
>  		new_ce = xcalloc(1, size);
>  		memcpy(new_ce->name, ce->name, len);
> diff --git a/unpack-trees.c b/unpack-trees.c
> index 9981dd3..abd0988 100644
> --- a/unpack-trees.c
> +++ b/unpack-trees.c
> @@ -1289,7 +1289,7 @@ static int verify_clean_subdirectory(struct cache_entry *ce,
>  	 * First let's make sure we do not have a local modification
>  	 * in that directory.
>  	 */
> -	namelen = strlen(ce->name);
> +	namelen = ce_namelen(ce);
>  	for (i = locate_in_src_index(ce, o);
>  	     i < o->src_index->cache_nr;
>  	     i++) {
Previous: Thomas Gummerer
Message 18 of 18 in “Replace ce_namelen() with a ce_namelen field”
  1. Replace ce_namelen() with a ce_namelen fieldThomas Gummerer, Jul 4, 2012
  2. Thomas RastJul 4, 2012
  3. Nguyen Thai Ngoc DuyJul 4, 2012
  4. Nguyen Thai Ngoc DuyJul 4, 2012
  5. Junio C HamanoJul 4, 2012
  6. Introduction of a ce_namelen fieldThomas Gummerer, Jul 6, 2012
  7. 1/2 Strip namelen out of ce_flags into a ce_namelen fieldThomas Gummerer, Jul 6, 2012
  8. Junio C HamanoJul 9, 2012
  9. 0/3 Introduction of a ce_namelen fieldThomas Gummerer, Jul 11, 2012
  10. 1/3 read-cache.c: Handle long filenames correctlyThomas Gummerer, Jul 11, 2012
  11. Nguyen Thai Ngoc DuyJul 11, 2012
  12. Junio C HamanoJul 11, 2012
  13. 2/3 Strip namelen out of ce_flags into a ce_namelen fieldThomas Gummerer, Jul 11, 2012
  14. 3/3 Replace strlen() with ce_namelen()Thomas Gummerer, Jul 11, 2012
  15. Junio C HamanoJul 11, 2012
  16. Junio C HamanoJul 11, 2012
  17. 2/2 Replace strlen() with ce_namelen()Thomas Gummerer, Jul 6, 2012
  18. Junio C HamanoJul 9, 2012

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.