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

Re: [PATCH 3/4] Introduce "abstract class" to make _locate_element() more independant of diff_rename_dst.

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Nov 4, 2010, 20:56 UTC
Message-ID
<20101104205655.GB18187@burratino>
In-Reply-To
<1288902795-8597-4-git-send-email-ydirson@altern.org>
Yann Dirson wrote:
Show 20 quoted lines
> --- a/diffcore-rename.c
> +++ b/diffcore-rename.c
> @@ -6,12 +6,16 @@
>  #include "diffcore.h"
>  #include "hash.h"
>  
> +
> +/* "Abstract class" for lists of filespecs */
> +struct dst_obj {
> +	struct diff_filespec *two;
> +};
>  #define locate_element(list,elem,insert_ok)			\
>  	_locate_element(elem, &list##_nr, &list##_alloc,	\
>  			sizeof(*list), insert_ok)
>  
> -/* Table of rename/copy destinations */
> -
> +/* Table of rename/copy destinations, "subclass" of dst_obj */
>  static struct diff_rename_dst {
>  	struct diff_filespec *two;
Nit: language lawyers might be happier with:
  struct dst_obj {
	struct diff_filespec *spec
  };
  struct diff_rename_dst {
	struct dst_obj two;
	...
  };
or
  typedef struct diff_filespec *dst_obj;
  struct diff_rename_dst {
	dst_obj two;
	...
  };
or
  struct diff_rename_dst {
	struct diff_filespec *two;
	...
  };
  ...
  struct diff_filespec **dst = (const char *) rename_dst + next * elem_size;
to avoid violating strict aliasing rules.
Meanwhile, something like
 #define container_of(ptr, type, member) \
	((type *)((char *) ptr - offsetof(type, member)))
can be useful for making the meaning more obvious when downcasting.
Previous: Yann DirsonNext: Yann Dirson
Message 7 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.