Skip to content

Commit 82dc42c

Browse files
ossilatorgitster
authored andcommitted
sequencer: simplify allocation of result array in todo_list_rearrange_squash()
The operation doesn't change the number of elements in the array, so we do not need to allocate the result piecewise. This moves the re-assignment of todo_list->alloc at the end slighly up, so it's right after the newly added assert which also refers to `nr` (and which indeed should come first). Also, the value is more likely to be still in a register at that point. Signed-off-by: Oswald Buddenhagen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a82fb66 commit 82dc42c

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
@@ -6233,7 +6233,7 @@ static int skip_fixupish(const char *subject, const char **p) {
62336233
int todo_list_rearrange_squash(struct todo_list *todo_list)
62346234
{
62356235
struct hashmap subject2item;
6236-
int rearranged = 0, *next, *tail, i, nr = 0, alloc = 0;
6236+
int rearranged = 0, *next, *tail, i, nr = 0;
62376237
char **subjects;
62386238
struct commit_todo_item commit_todo;
62396239
struct todo_item *items = NULL;
@@ -6345,6 +6345,8 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
63456345
}
63466346

63476347
if (rearranged) {
6348+
ALLOC_ARRAY(items, todo_list->nr);
6349+
63486350
for (i = 0; i < todo_list->nr; i++) {
63496351
enum todo_command command = todo_list->items[i].command;
63506352
int cur = i;
@@ -6357,16 +6359,15 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
63576359
continue;
63586360

63596361
while (cur >= 0) {
6360-
ALLOC_GROW(items, nr + 1, alloc);
63616362
items[nr++] = todo_list->items[cur];
63626363
cur = next[cur];
63636364
}
63646365
}
63656366

6367+
assert(nr == todo_list->nr);
6368+
todo_list->alloc = nr;
63666369
FREE_AND_NULL(todo_list->items);
63676370
todo_list->items = items;
6368-
todo_list->nr = nr;
6369-
todo_list->alloc = alloc;
63706371
}
63716372

63726373
free(next);

0 commit comments

Comments
 (0)