From: Junio C Hamano <gitster@pobox.com>
To: "Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Phillip Wood <phillip.wood@dunelm.org.uk>
Subject: Re: [PATCH 1/2] add -p: use ALLOC_GROW_BY instead of ALLOW_GROW
Date: Mon, 17 Aug 2020 11:35:09 -0700 [thread overview]
Message-ID: <xmqqy2md15pe.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <ae6ace43af9b25ee8f67b01ed1ec50064c8b006f.1597670589.git.gitgitgadget@gmail.com> (Phillip Wood via GitGitGadget's message of "Mon, 17 Aug 2020 13:23:07 +0000")
"Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> This simplifies the code slightly, especially the third case where
> hunk_nr was incremented a few lines before ALLOC_GROW().
OK, we lose memset()s that appear to be separate but is a part of
adding more elements. Makes sense.
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
> add-patch.c | 13 ++++---------
> 1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/add-patch.c b/add-patch.c
> index f899389e2c..a15fa407be 100644
> --- a/add-patch.c
> +++ b/add-patch.c
> @@ -457,11 +457,9 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
> eol = pend;
>
> if (starts_with(p, "diff ")) {
> - s->file_diff_nr++;
> - ALLOC_GROW(s->file_diff, s->file_diff_nr,
> + ALLOC_GROW_BY(s->file_diff, s->file_diff_nr, 1,
> file_diff_alloc);
> file_diff = s->file_diff + s->file_diff_nr - 1;
> - memset(file_diff, 0, sizeof(*file_diff));
> hunk = &file_diff->head;
> hunk->start = p - plain->buf;
> if (colored_p)
> @@ -483,11 +481,9 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
> */
> hunk->splittable_into++;
>
> - file_diff->hunk_nr++;
> - ALLOC_GROW(file_diff->hunk, file_diff->hunk_nr,
> + ALLOC_GROW_BY(file_diff->hunk, file_diff->hunk_nr, 1,
> file_diff->hunk_alloc);
> hunk = file_diff->hunk + file_diff->hunk_nr - 1;
> - memset(hunk, 0, sizeof(*hunk));
>
> hunk->start = p - plain->buf;
> if (colored)
> @@ -511,7 +507,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
> if (file_diff->mode_change)
> BUG("double mode change?\n\n%.*s",
> (int)(eol - plain->buf), plain->buf);
> - if (file_diff->hunk_nr++)
> + if (file_diff->hunk_nr)
> BUG("mode change in the middle?\n\n%.*s",
> (int)(eol - plain->buf), plain->buf);
>
> @@ -520,9 +516,8 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
> * is _part of_ the header "hunk".
> */
> file_diff->mode_change = 1;
> - ALLOC_GROW(file_diff->hunk, file_diff->hunk_nr,
> + ALLOC_GROW_BY(file_diff->hunk, file_diff->hunk_nr, 1,
> file_diff->hunk_alloc);
> - memset(file_diff->hunk, 0, sizeof(struct hunk));
> file_diff->hunk->start = p - plain->buf;
> if (colored_p)
> file_diff->hunk->colored_start =
next prev parent reply other threads:[~2020-08-17 18:35 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-17 13:23 [PATCH 0/2] add p in C tweaks Phillip Wood via GitGitGadget
2020-08-17 13:23 ` [PATCH 1/2] add -p: use ALLOC_GROW_BY instead of ALLOW_GROW Phillip Wood via GitGitGadget
2020-08-17 18:35 ` Junio C Hamano [this message]
2020-08-17 13:23 ` [PATCH 2/2] add -p: fix checking of user input Phillip Wood via GitGitGadget
2020-08-18 6:38 ` Johannes Schindelin
2020-08-18 6:39 ` [PATCH 0/2] add p in C tweaks Johannes Schindelin
2020-08-18 19:44 ` Junio C Hamano
2020-08-19 9:59 ` Phillip Wood
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=xmqqy2md15pe.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=phillip.wood@dunelm.org.uk \
/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).