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

Re: [PATCH v4 05/14] diff.c: use ALLOC_GROW()

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 3, 2014, 22:48 UTC
Message-ID
<xmqq1tyioq4e.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1393885922-21616-6-git-send-email-dmitrys.dolzhenko@yandex.ru>
"Dmitry S. Dolzhenko" <dmitrys.dolzhenko@yandex.ru> writes:
> Use ALLOC_GROW() instead inline code in
> diffstat_add() and diff_q()
"...instead of open coding it in..." may read better.
Show 35 quoted lines
>
> Signed-off-by: Dmitry S. Dolzhenko <dmitrys.dolzhenko@yandex.ru>
> ---
>  diff.c | 12 ++----------
>  1 file changed, 2 insertions(+), 10 deletions(-)
>
> diff --git a/diff.c b/diff.c
> index e800666..aebdfda 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -1361,11 +1361,7 @@ static struct diffstat_file *diffstat_add(struct diffstat_t *diffstat,
>  {
>  	struct diffstat_file *x;
>  	x = xcalloc(sizeof (*x), 1);
> -	if (diffstat->nr == diffstat->alloc) {
> -		diffstat->alloc = alloc_nr(diffstat->alloc);
> -		diffstat->files = xrealloc(diffstat->files,
> -				diffstat->alloc * sizeof(x));
> -	}
> +	ALLOC_GROW(diffstat->files, diffstat->nr + 1, diffstat->alloc);
>  	diffstat->files[diffstat->nr++] = x;
>  	if (name_b) {
>  		x->from_name = xstrdup(name_a);
> @@ -3965,11 +3961,7 @@ struct diff_queue_struct diff_queued_diff;
>  
>  void diff_q(struct diff_queue_struct *queue, struct diff_filepair *dp)
>  {
> -	if (queue->alloc <= queue->nr) {
> -		queue->alloc = alloc_nr(queue->alloc);
> -		queue->queue = xrealloc(queue->queue,
> -					sizeof(dp) * queue->alloc);
> -	}
> +	ALLOC_GROW(queue->queue, queue->nr + 1, queue->alloc);
>  	queue->queue[queue->nr++] = dp;
>  }
Previous: Dmitry S. DolzhenkoNext: Dmitry S. Dolzhenko
Message 7 of 17 in “Use ALLOC_GROW() instead of inline code”
  1. 00/14 Use ALLOC_GROW() instead of inline codeDmitry S. Dolzhenko, Mar 3, 2014
  2. 01/14 builtin/pack-objects.c: use ALLOC_GROW() in check_pbase_path()Dmitry S. Dolzhenko, Mar 3, 2014
  3. 02/14 bundle.c: use ALLOC_GROW() in add_to_ref_list()Dmitry S. Dolzhenko, Mar 3, 2014
  4. 03/14 cache-tree.c: use ALLOC_GROW() in find_subtree()Dmitry S. Dolzhenko, Mar 3, 2014
  5. 04/14 commit.c: use ALLOC_GROW() in register_commit_graft()Dmitry S. Dolzhenko, Mar 3, 2014
  6. 05/14 diff.c: use ALLOC_GROW()Dmitry S. Dolzhenko, Mar 3, 2014
  7. Junio C HamanoMar 3, 2014
  8. 06/14 diffcore-rename.c: use ALLOC_GROW()Dmitry S. Dolzhenko, Mar 3, 2014
  9. 07/14 patch-ids.c: use ALLOC_GROW() in add_commit()Dmitry S. Dolzhenko, Mar 3, 2014
  10. 08/14 replace_object.c: use ALLOC_GROW() in register_replace_object()Dmitry S. Dolzhenko, Mar 3, 2014
  11. 09/14 reflog-walk.c: use ALLOC_GROW()Dmitry S. Dolzhenko, Mar 3, 2014
  12. 10/14 dir.c: use ALLOC_GROW() in create_simplify()Dmitry S. Dolzhenko, Mar 3, 2014
  13. 11/14 attr.c: use ALLOC_GROW() in handle_attr_line()Dmitry S. Dolzhenko, Mar 3, 2014
  14. 12/14 builtin/mktree.c: use ALLOC_GROW() in append_to_tree()Dmitry S. Dolzhenko, Mar 3, 2014
  15. 13/14 read-cache.c: use ALLOC_GROW() in add_index_entry()Dmitry S. Dolzhenko, Mar 3, 2014
  16. 14/14 sha1_file.c: use ALLOC_GROW() in pretend_sha1_file()Dmitry S. Dolzhenko, Mar 3, 2014
  17. Junio C HamanoMar 3, 2014

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.