git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: Git List <git@vger.kernel.org>
Subject: Re: [PATCH] commit: move clear_commit_marks_many() loop body to clear_commit_marks()
Date: Sun, 23 Mar 2025 22:50:54 -0700	[thread overview]
Message-ID: <xmqqo6xrou2p.fsf@gitster.g> (raw)
In-Reply-To: <80bfd7a9-904c-49d8-a367-ca268c096a9f@web.de> ("René Scharfe"'s message of "Sun, 23 Mar 2025 10:53:21 +0100")

René Scharfe <l.s.r@web.de> writes:

> clear_commit_marks_many() clears multiple commits one by one.  Move the
> code for handling a single commit to clear_commit_marks() and call it
> instead of the other way around, to simplify the code.
>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
>  commit.c | 16 +++++++---------
>  1 file changed, 7 insertions(+), 9 deletions(-)

I _suspect_ that the original motivation of the current code layout
was hoping that with more information at hand, the *_many() variant
could be optimized to work on multiple things at once, which may be
more efficient than doing things one-by-one, but such an optimization
never materialized.

And it is much simpler and easier to read what goes on in which
function if these two functions are rewritten the way you just did.
It is crystal clear that there is nothing clever in the *_many()
variant.

Thanks.

> diff --git a/commit.c b/commit.c
> index 6efdb03997..425503bb9f 100644
> --- a/commit.c
> +++ b/commit.c
> @@ -780,19 +780,17 @@ static void clear_commit_marks_1(struct commit_list **plist,
>
>  void clear_commit_marks_many(size_t nr, struct commit **commit, unsigned int mark)
>  {
> -	for (size_t i = 0; i < nr; i++) {
> -		struct commit_list *list = NULL;
> -
> -		clear_commit_marks_1(&list, *commit, mark);
> -		while (list)
> -			clear_commit_marks_1(&list, pop_commit(&list), mark);
> -		commit++;
> -	}
> +	for (size_t i = 0; i < nr; i++)
> +		clear_commit_marks(commit[i], mark);
>  }
>
>  void clear_commit_marks(struct commit *commit, unsigned int mark)
>  {
> -	clear_commit_marks_many(1, &commit, mark);
> +	struct commit_list *list = NULL;
> +
> +	clear_commit_marks_1(&list, commit, mark);
> +	while (list)
> +		clear_commit_marks_1(&list, pop_commit(&list), mark);
>  }
>
>  struct commit *pop_commit(struct commit_list **stack)
> --
> 2.49.0

      reply	other threads:[~2025-03-24  5:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-23  9:53 [PATCH] commit: move clear_commit_marks_many() loop body to clear_commit_marks() René Scharfe
2025-03-24  5:50 ` Junio C Hamano [this message]

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqo6xrou2p.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    /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.
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 NNTP newsgroup(s).