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

Re: [PATCH 1/4] Start to replace locate_rename_dst() with a generic function.

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Nov 4, 2010, 20:45 UTC
Message-ID
<20101104204555.GA18187@burratino>
In-Reply-To
<1288902795-8597-2-git-send-email-ydirson@altern.org>
Yann Dirson wrote:
Show 10 quoted lines
> --- a/diffcore-rename.c
> +++ b/diffcore-rename.c
> @@ -6,6 +6,10 @@
>  #include "diffcore.h"
>  #include "hash.h"
>  
> +#define locate_element(list,elem,insert_ok)			\
> +	_locate_element(elem, &list##_nr, &list##_alloc,	\
> +			insert_ok)
> +
Is this syntactic sugar needed?
 static struct diff_rename_dst *locate_rename_dst(struct diff_filespec *two,
						  insert_ok)
 {
	return locate_element(&rename_dst_nr, &rename_dst_alloc, elem, insert_ok);
 }

takes more advantage of the compiler's typechecking and looks easy enough to read.

Since this is local to diffcore-rename, I don't mind the locate_element() name, but if this is to be used more widely I think it would need to be named more precisely. (find_or_insert_in_array()?)

> @@ -13,14 +17,17 @@ static struct diff_rename_dst {
[...]
Show 11 quoted lines
> -static struct diff_rename_dst *locate_rename_dst(struct diff_filespec *two,
> -						 int insert_ok)
> +static struct diff_rename_dst *_locate_element(struct diff_filespec *two,
> +					       int *elem_nr_p, int *elem_alloc_p,
> +					       int insert_ok)
>  {
>  	int first, last;
>  
>  	first = 0;
> -	last = rename_dst_nr;
> +	last = (*elem_nr_p);

I guess these parentheses came from search+replace? It's more readable without them.

[...]
> +	(*elem_nr_p)++;
Except for this one.
Generally, the approach seems sane so far.
Previous: Yann DirsonNext: Yann Dirson
Message 3 of 8 in “generalizing sorted-array handling”
  1. generalizing sorted-array handlingYann Dirson, Nov 4, 2010
  2. 1/4 Start to replace locate_rename_dst() with a generic function.Yann Dirson, Nov 4, 2010
  3. Jonathan NiederNov 4, 2010
  4. Yann DirsonNov 4, 2010
  5. 2/4 Abstract _locate_element() some more with elem_size parameter.Yann Dirson, Nov 4, 2010
  6. 3/4 Introduce "abstract class" to make _locate_element() more independant of diff_rename_dst.Yann Dirson, Nov 4, 2010
  7. Jonathan NiederNov 4, 2010
  8. 4/4 Remove remaining rename_dst references in _locate_element() and pass a pointer to it.Yann Dirson, Nov 4, 2010

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.