From: Jeff King <peff@peff.net>
To: "SZEDER Gábor" <szeder.dev@gmail.com>
Cc: Junio C Hamano <gitster@pobox.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 17:44:10 -0500 [thread overview]
Message-ID: <20180122224410.GA21604@sigill.intra.peff.net> (raw)
In-Reply-To: <20180122175009.20178-1-szeder.dev@gmail.com>
On Mon, Jan 22, 2018 at 06:50:09PM +0100, SZEDER Gábor wrote:
> Use the helper macro MOVE_ARRAY to move arrays. This is shorter and
> safer, as it automatically infers the size of elements.
>
> Patch generated by Coccinelle and contrib/coccinelle/array.cocci in
> Travis CI's static analysis build job.
Seems pretty straightforward. One thing I did notice...
> diff --git a/cache-tree.c b/cache-tree.c
> index e03e72c34a..18946aa458 100644
> --- a/cache-tree.c
> +++ b/cache-tree.c
> @@ -84,9 +84,8 @@ static struct cache_tree_sub *find_subtree(struct cache_tree *it,
> down->namelen = pathlen;
>
> if (pos < it->subtree_nr)
> - memmove(it->down + pos + 1,
> - it->down + pos,
> - sizeof(down) * (it->subtree_nr - pos - 1));
> + MOVE_ARRAY(it->down + pos + 1, it->down + pos,
> + it->subtree_nr - pos - 1);
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);
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.
-Peff
next prev parent reply other threads:[~2018-01-22 22:44 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 [this message]
2018-01-22 23:26 ` Junio C Hamano
2018-01-22 23:34 ` Jeff King
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=20180122224410.GA21604@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).