git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: "SZEDER Gábor" <szeder.dev@gmail.com>,
	"Rene Scharfe" <l.s.r@web.de>,
	"Stefan Beller" <sbeller@google.com>,
	"Lars Schneider" <larsxschneider@gmail.com>,
	git@vger.kernel.org
Subject: Re: [PATCH] Use MOVE_ARRAY
Date: Mon, 22 Jan 2018 18:34:26 -0500	[thread overview]
Message-ID: <20180122233426.GA27144@sigill.intra.peff.net> (raw)
In-Reply-To: <xmqq372xjwzg.fsf@gitster.mtv.corp.google.com>

On Mon, Jan 22, 2018 at 03:26:59PM -0800, Junio C Hamano wrote:

> Jeff King <peff@peff.net> writes:
> 
> > 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 ;-)

Yeah, you'd need to know the "alloc" number to right-shift correctly,
since by definition we're pushing off the end of a->nr. Left-shifts just
need to make sure they don't go past "0", which we can do here, but I'd
think they're pretty uncommon.

The right macro level may actually be something more like "make room for
N items at pos". E.g.:

  #define CREATE_ARRAY_HOLE(a, nr, alloc, pos, slots) do { \
          ALLOC_GROW(a, nr + slots, alloc);
	  MOVE_ARRAY(a + pos + slots, a + pos, nr - pos - slots);
  } while (0)

but I didn't investigate the surrounding code. And it surely would need
a catchier name. ;)

-Peff

      reply	other threads:[~2018-01-22 23:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-15 17:10 [PATCH] describe: use strbuf_add_unique_abbrev() for adding short hashes René Scharfe
2018-01-16 13:48 ` Derrick Stolee
2018-01-16 17:11 ` SZEDER Gábor
2018-01-18 21:40   ` René Scharfe
2018-01-18 22:40     ` SZEDER Gábor
2018-01-18 23:02       ` Lars Schneider
2018-01-19 17:53       ` René Scharfe
2018-01-22 17:50         ` [PATCH] Use MOVE_ARRAY SZEDER Gábor
2018-01-22 22:44           ` Jeff King
2018-01-22 23:26             ` Junio C Hamano
2018-01-22 23:34               ` Jeff King [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180122233426.GA27144@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    --cc=larsxschneider@gmail.com \
    --cc=sbeller@google.com \
    --cc=szeder.dev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).