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

Re: [PATCH] Use MOVE_ARRAY

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 22, 2018, 23:26 UTC
Message-ID
<xmqq372xjwzg.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20180122224410.GA21604@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 7 quoted lines
> Most of these are "shift part of the array". I wonder if it would make
> sense to encapsulate that pattern in a helper, like:
>
>   #define SHIFT_ARRAY(a, nr, pos, slots) \
>     MOVE_ARRAY(a + pos + slots, a + pos, nr - pos - slots)
>   ...
>   SHIFT_ARRAY(it->down, it->subtree_nr, pos, 1);

Exactly my thought when I was queuing it, but I was wondering about this more from "can we use the higher level abstraction for reducing errors?" point of view. If we are shifting an array by 3 slots to the right, we should at least have enough slots allocated to hold them (i.e. a->nr - a->alloc must be 3 or more). But after realizing that the level these macros operate at is still a bit too low to do something like that, I quickly lost interest ;-)

> I'm not sure if that's more readable because it describes a higher-level
> operation, or if it's less because it adds yet another non-standard
> helper for the reader to learn.

Yeah, conflicting goals. It indeed is easier to see what is going on when reading the code, once the reader gets used to them.

Thanks.
Previous: Jeff KingNext: Jeff King
Message 10 of 11 in “describe: use strbuf_add_unique_abbrev() for adding short hashes”
  1. describe: use strbuf_add_unique_abbrev() for adding short hashesRené Scharfe, Jan 15, 2018
  2. Derrick StoleeJan 16, 2018
  3. SZEDER GáborJan 16, 2018
  4. René ScharfeJan 18, 2018
  5. SZEDER GáborJan 18, 2018
  6. Lars SchneiderJan 18, 2018
  7. René ScharfeJan 19, 2018
  8. Use MOVE_ARRAYSZEDER Gábor, Jan 22, 2018
  9. Jeff KingJan 22, 2018
  10. Junio C HamanoJan 22, 2018
  11. Jeff KingJan 22, 2018

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.