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

Re: [PATCH 2/2] use COPY_ARRAY for copying arrays

From
Derrick Stolee <stolee@gmail.com>
Date
Jun 17, 2019, 01:14 UTC
Message-ID
<d51041e1-c931-146f-51e7-8a51655dcaa0@gmail.com>
In-Reply-To
<e09e49a6-8f6d-1f26-005a-bec5f99414dd@web.de>
On 6/15/2019 2:36 PM, René Scharfe wrote:
> Convert calls of memcpy(3) to use COPY_ARRAY, which shortens and
> simplifies the code a bit.
These changes do look simpler. Thanks!
> Patch generated by Coccinelle and contrib/coccinelle/array.cocci.
And this auto-generation is particularly useful!
Show 19 quoted lines
> 
> Signed-off-by: Rene Scharfe <l.s.r@web.de>
> ---
>  fast-import.c | 2 +-
>  kwset.c       | 2 +-
>  packfile.c    | 6 +++---
>  pretty.c      | 4 ++--
>  4 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/kwset.c b/kwset.c
> index 4fb6455aca..090ffcafa2 100644
> --- a/kwset.c
> +++ b/kwset.c
> @@ -475,7 +475,7 @@ kwsprep (kwset_t kws)
>  	for (i = 0; i < NCHAR; ++i)
>  	  kwset->next[i] = next[U(trans[i])];
>        else
> -	memcpy(kwset->next, next, NCHAR * sizeof(struct trie *));
> +	COPY_ARRAY(kwset->next, next, NCHAR);

I was unfamiliar with kwset.c, so I took a look and noticed that it was adapted from GNU grep, so this change takes us even farther from the original source (and closer to Git source conventions).

I think this is the right thing to do, but thought I'd point it out in case anyone thought differently.

Both patches LGTM.

Thanks, -Stolee

Previous: René Scharfe
Message 3 of 3 in “coccinelle: use COPY_ARRAY for copying arrays”
  1. 1/2 coccinelle: use COPY_ARRAY for copying arraysRené Scharfe, Jun 15, 2019
  2. 2/2 use COPY_ARRAY for copying arraysRené Scharfe, Jun 15, 2019
  3. Derrick StoleeJun 17, 2019

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.