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

Re: [PATCH] merge-recursive.c: use QSORT macro

From
Jeff King <peff@peff.net>
Date
Nov 22, 2016, 17:49 UTC
Message-ID
<20161122174946.jy5at4g7rifu3und@sigill.intra.peff.net>
In-Reply-To
<20161122123019.7169-1-pclouds@gmail.com>
On Tue, Nov 22, 2016 at 07:30:19PM +0700, Nguyễn Thái Ngọc Duy wrote:
Show 16 quoted lines
> This is the follow up of rs/qsort series, merged in b8688ad (Merge
> branch 'rs/qsort' - 2016-10-10), where coccinelle was used to do
> automatic transformation.
> 
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>   coccinelle missed this place, understandably, because it can't know
>   that
>   
>       sizeof(*entries->items)
>   
>   is the same as
>   
>       sizeof(*df_name_compare.items)
>   
>   without some semantic analysis.

That made me wonder why "entries" is used at all. Does it point to the same struct? But no, df_name_compare is a string list we create with the same list of strings.

Which is why...
> -	qsort(df_sorted_entries.items, entries->nr, sizeof(*entries->items),
> +	QSORT(df_sorted_entries.items, entries->nr,
>  	      string_list_df_name_compare);

...it's OK to use entries->nr here, and not df_sorted_entries.nr. It still seems a bit odd, though. Maybe it's worth making this:

  QSORT(df_sorted_entries.items, df_sorted_entries.nr,
        string_list_df_name_compare);
while we're at it. Another possibility is:
  df_sorted_entries.cmp = string_list_df_name_compare;
  string_list_sort(&df_sorted_entries);
It's not any shorter, but maybe it's conceptually simpler.
-Peff
Previous: Nguyễn Thái Ngọc DuyNext: Duy Nguyen
Message 2 of 8 in “merge-recursive.c: use QSORT macro”
  1. merge-recursive.c: use QSORT macroNguyễn Thái Ngọc Duy, Nov 22, 2016
  2. Jeff KingNov 22, 2016
  3. Duy NguyenNov 23, 2016
  4. Junio C HamanoNov 23, 2016
  5. merge-recursive.c: use string_list_sort instead of qsortNguyễn Thái Ngọc Duy, Nov 24, 2016
  6. Jeff KingNov 24, 2016
  7. Duy NguyenNov 25, 2016
  8. Jeff KingNov 25, 2016

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.