From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.6 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id DFCA21F404 for ; Mon, 22 Jan 2018 22:44:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751142AbeAVWoO (ORCPT ); Mon, 22 Jan 2018 17:44:14 -0500 Received: from cloud.peff.net ([104.130.231.41]:53722 "HELO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751048AbeAVWoN (ORCPT ); Mon, 22 Jan 2018 17:44:13 -0500 Received: (qmail 7733 invoked by uid 109); 22 Jan 2018 22:44:14 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with SMTP; Mon, 22 Jan 2018 22:44:14 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 11609 invoked by uid 111); 22 Jan 2018 22:44:50 -0000 Received: from sigill.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.7) by peff.net (qpsmtpd/0.94) with (ECDHE-RSA-AES256-GCM-SHA384 encrypted) SMTP; Mon, 22 Jan 2018 17:44:50 -0500 Authentication-Results: peff.net; auth=none Received: by sigill.intra.peff.net (sSMTP sendmail emulation); Mon, 22 Jan 2018 17:44:10 -0500 Date: Mon, 22 Jan 2018 17:44:10 -0500 From: Jeff King To: SZEDER =?utf-8?B?R8OhYm9y?= Cc: Junio C Hamano , Rene Scharfe , Stefan Beller , Lars Schneider , git@vger.kernel.org Subject: Re: [PATCH] Use MOVE_ARRAY Message-ID: <20180122224410.GA21604@sigill.intra.peff.net> References: <20180122175009.20178-1-szeder.dev@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180122175009.20178-1-szeder.dev@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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