Skip to content

Commit 9df27c2

Browse files
szedergitster
authored andcommitted
line-log: get rid of the parents array in process_ranges_merge_commit()
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent a3540ed commit 9df27c2

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

line-log.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,6 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
12031203
struct line_log_data *range)
12041204
{
12051205
struct line_log_data **cand;
1206-
struct commit **parents;
12071206
struct commit_list *p;
12081207
int i;
12091208
int nparents = commit_list_count(commit->parents);
@@ -1213,15 +1212,15 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
12131212
nparents = 1;
12141213

12151214
CALLOC_ARRAY(cand, nparents);
1216-
ALLOC_ARRAY(parents, nparents);
12171215

1218-
p = commit->parents;
1219-
for (i = 0; i < nparents; i++) {
1216+
for (p = commit->parents, i = 0;
1217+
p && i < nparents;
1218+
p = p->next, i++) {
1219+
struct commit *parent = p->item;
12201220
struct diff_queue_struct diffqueue = DIFF_QUEUE_INIT;
12211221
int changed;
1222-
parents[i] = p->item;
1223-
p = p->next;
1224-
queue_diffs(range, &rev->diffopt, &diffqueue, commit, parents[i]);
1222+
1223+
queue_diffs(range, &rev->diffopt, &diffqueue, commit, parent);
12251224

12261225
changed = process_all_files(&cand[i], rev, &diffqueue, range);
12271226
diff_queue_clear(&diffqueue);
@@ -1230,9 +1229,9 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
12301229
* This parent can take all the blame, so we
12311230
* don't follow any other path in history
12321231
*/
1233-
add_line_range(rev, parents[i], cand[i]);
1232+
add_line_range(rev, parent, cand[i]);
12341233
free_commit_list(commit->parents);
1235-
commit_list_append(parents[i], &commit->parents);
1234+
commit_list_append(parent, &commit->parents);
12361235

12371236
ret = 0;
12381237
goto out;
@@ -1243,14 +1242,15 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
12431242
* No single parent took the blame. We add the candidates
12441243
* from the above loop to the parents.
12451244
*/
1246-
for (i = 0; i < nparents; i++)
1247-
add_line_range(rev, parents[i], cand[i]);
1245+
for (p = commit->parents, i = 0;
1246+
p && i < nparents;
1247+
p = p->next, i++)
1248+
add_line_range(rev, p->item, cand[i]);
12481249

12491250
ret = 1;
12501251

12511252
out:
12521253
clear_commit_line_range(rev, commit);
1253-
free(parents);
12541254
for (i = 0; i < nparents; i++) {
12551255
if (!cand[i])
12561256
continue;

0 commit comments

Comments
 (0)