Skip to content

Commit e9608bb

Browse files
committed
Merge branch 'ob/sequencer-rearrange-cleanup'
Code clean-up. * ob/sequencer-rearrange-cleanup: sequencer: simplify allocation of result array in todo_list_rearrange_squash()
2 parents f5f23a4 + 82dc42c commit e9608bb

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

sequencer.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6245,7 +6245,7 @@ static int skip_fixupish(const char *subject, const char **p) {
62456245
int todo_list_rearrange_squash(struct todo_list *todo_list)
62466246
{
62476247
struct hashmap subject2item;
6248-
int rearranged = 0, *next, *tail, i, nr = 0, alloc = 0;
6248+
int rearranged = 0, *next, *tail, i, nr = 0;
62496249
char **subjects;
62506250
struct commit_todo_item commit_todo;
62516251
struct todo_item *items = NULL;
@@ -6357,6 +6357,8 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
63576357
}
63586358

63596359
if (rearranged) {
6360+
ALLOC_ARRAY(items, todo_list->nr);
6361+
63606362
for (i = 0; i < todo_list->nr; i++) {
63616363
enum todo_command command = todo_list->items[i].command;
63626364
int cur = i;
@@ -6369,16 +6371,15 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
63696371
continue;
63706372

63716373
while (cur >= 0) {
6372-
ALLOC_GROW(items, nr + 1, alloc);
63736374
items[nr++] = todo_list->items[cur];
63746375
cur = next[cur];
63756376
}
63766377
}
63776378

6379+
assert(nr == todo_list->nr);
6380+
todo_list->alloc = nr;
63786381
FREE_AND_NULL(todo_list->items);
63796382
todo_list->items = items;
6380-
todo_list->nr = nr;
6381-
todo_list->alloc = alloc;
63826383
}
63836384

63846385
free(next);

0 commit comments

Comments
 (0)