From: "SZEDER Gábor" <szeder.dev@gmail.com>
To: git@vger.kernel.org
Cc: "SZEDER Gábor" <szeder.dev@gmail.com>
Subject: [PATCH 2/4] line-log: get rid of the parents array in process_ranges_merge_commit()
Date: Sun, 24 Aug 2025 21:06:42 +0200 [thread overview]
Message-ID: <20250824190644.2573279-3-szeder.dev@gmail.com> (raw)
In-Reply-To: <20250824190644.2573279-1-szeder.dev@gmail.com>
We can easily iterate through the parents of a merge commit without
turning the list of parents into a dynamically allocated array of
parents, so let's do so. This way we can avoid a memory allocation
for each processed merge commit, though its effect on runtime seems to
be unmeasurable.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
line-log.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/line-log.c b/line-log.c
index cf30915c94..b2a31ae956 100644
--- a/line-log.c
+++ b/line-log.c
@@ -1203,7 +1203,6 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
struct line_log_data *range)
{
struct line_log_data **cand;
- struct commit **parents;
struct commit_list *p;
int i;
int nparents = commit_list_count(commit->parents);
@@ -1213,15 +1212,15 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
nparents = 1;
CALLOC_ARRAY(cand, nparents);
- ALLOC_ARRAY(parents, nparents);
- p = commit->parents;
- for (i = 0; i < nparents; i++) {
+ for (p = commit->parents, i = 0;
+ p && i < nparents;
+ p = p->next, i++) {
+ struct commit *parent = p->item;
struct diff_queue_struct diffqueue = DIFF_QUEUE_INIT;
int changed;
- parents[i] = p->item;
- p = p->next;
- queue_diffs(range, &rev->diffopt, &diffqueue, commit, parents[i]);
+
+ queue_diffs(range, &rev->diffopt, &diffqueue, commit, parent);
changed = process_all_files(&cand[i], rev, &diffqueue, range);
diff_queue_clear(&diffqueue);
@@ -1230,9 +1229,9 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
* This parent can take all the blame, so we
* don't follow any other path in history
*/
- add_line_range(rev, parents[i], cand[i]);
+ add_line_range(rev, parent, cand[i]);
free_commit_list(commit->parents);
- commit_list_append(parents[i], &commit->parents);
+ commit_list_append(parent, &commit->parents);
ret = 0;
goto out;
@@ -1243,14 +1242,15 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
* No single parent took the blame. We add the candidates
* from the above loop to the parents.
*/
- for (i = 0; i < nparents; i++)
- add_line_range(rev, parents[i], cand[i]);
+ for (p = commit->parents, i = 0;
+ p && i < nparents;
+ p = p->next, i++)
+ add_line_range(rev, p->item, cand[i]);
ret = 1;
out:
clear_commit_line_range(rev, commit);
- free(parents);
for (i = 0; i < nparents; i++) {
if (!cand[i])
continue;
--
2.51.0.433.g1a66b3fb12
next prev parent reply other threads:[~2025-08-24 19:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-24 19:06 [PATCH 0/4] line-log: optimize merge commit processing SZEDER Gábor
2025-08-24 19:06 ` [PATCH 1/4] line-log: avoid unnecessary tree diffs when processing merge commits SZEDER Gábor
2025-08-25 14:13 ` Derrick Stolee
2025-08-25 15:35 ` Junio C Hamano
2025-08-28 20:27 ` SZEDER Gábor
2025-08-24 19:06 ` SZEDER Gábor [this message]
2025-08-24 19:06 ` [PATCH 3/4] line-log: initialize diff queue in process_ranges_ordinary_commit() SZEDER Gábor
2025-08-24 19:06 ` [PATCH 4/4] line-log: simplify condition checking for merge commits SZEDER Gábor
2025-08-25 20:57 ` Junio C Hamano
2025-08-25 21:43 ` Derrick Stolee
2025-08-25 21:57 ` Junio C Hamano
2025-08-25 14:16 ` [PATCH 0/4] line-log: optimize merge commit processing Derrick Stolee
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=20250824190644.2573279-3-szeder.dev@gmail.com \
--to=szeder.dev@gmail.com \
--cc=git@vger.kernel.org \
/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).