Re: [PATCH] Use MOVE_ARRAY

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux