Skip to content

Commit 586d8b5

Browse files
szederttaylorr
authored andcommitted
diff.c: use diff_free_queue()
Use diff_free_queue() instead of open-coding it. This shortens the code and make it less repetitive. Note that the second hunk in diff_flush() is interesting, because the 'free_queue' label separates the loop freeing the queue's filepairs from free()-ing the queue's internal array. This is somewhat suspicious, but it was not an issue before: there is only one place from where we jump to this label with a goto, and that is protected by an 'if (!q->nr && ...)' condition, i.e. we only skipped the loop freeing the filepairs when there were no filepairs in the queue to begin with. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent ef84222 commit 586d8b5

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

diff.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6337,13 +6337,9 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
63376337
int diff_flush_patch_id(struct diff_options *options, struct object_id *oid, int diff_header_only)
63386338
{
63396339
struct diff_queue_struct *q = &diff_queued_diff;
6340-
int i;
63416340
int result = diff_get_patch_id(options, oid, diff_header_only);
63426341

6343-
for (i = 0; i < q->nr; i++)
6344-
diff_free_filepair(q->queue[i]);
6345-
6346-
free(q->queue);
6342+
diff_free_queue(q);
63476343
DIFF_QUEUE_CLEAR(q);
63486344

63496345
return result;
@@ -6612,10 +6608,8 @@ void diff_flush(struct diff_options *options)
66126608
if (output_format & DIFF_FORMAT_CALLBACK)
66136609
options->format_callback(q, options, options->format_callback_data);
66146610

6615-
for (i = 0; i < q->nr; i++)
6616-
diff_free_filepair(q->queue[i]);
66176611
free_queue:
6618-
free(q->queue);
6612+
diff_free_queue(q);
66196613
DIFF_QUEUE_CLEAR(q);
66206614
diff_free(options);
66216615

0 commit comments

Comments
 (0)