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

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

From
Duy Nguyen <pclouds@gmail.com>
Date
Nov 23, 2016, 09:43 UTC
Message-ID
<CACsJy8BFRroifr0OL0O5OZjkPkndeZzVYCkg9vCNk+7Ee4zouA@mail.gmail.com>
In-Reply-To
<20161122174946.jy5at4g7rifu3und@sigill.intra.peff.net>
On Wed, Nov 23, 2016 at 12:49 AM, Jeff King <peff@peff.net> wrote:
Show 31 quoted lines
> On Tue, Nov 22, 2016 at 07:30:19PM +0700, Nguyễn Thái Ngọc Duy wrote:
>
>> 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.
Argh.. I completely overlooked that entries->nr !
Show 11 quoted lines
> 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.
Agreed. Shall I re-roll with this?
-- 
Duy
Previous: Jeff KingNext: Junio C Hamano
Message 3 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.