Skip to content

Commit 3bc7a05

Browse files
rscharfegitster
authored andcommitted
walker: avoid quadratic list insertion in mark_complete
Similar to 1644524 (fetch-pack: avoid quadratic list insertion in mark_complete), sort only after all refs are collected instead of while inserting. The result is the same, but it's more efficient that way. The difference will only be measurable in repositories with a large number of refs. Signed-off-by: Rene Scharfe <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e8d1dfe commit 3bc7a05

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

walker.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ static int mark_complete(const char *path, const unsigned char *sha1, int flag,
204204
struct commit *commit = lookup_commit_reference_gently(sha1, 1);
205205
if (commit) {
206206
commit->object.flags |= COMPLETE;
207-
commit_list_insert_by_date(commit, &complete);
207+
commit_list_insert(commit, &complete);
208208
}
209209
return 0;
210210
}
@@ -269,8 +269,10 @@ int walker_fetch(struct walker *walker, int targets, char **target,
269269
}
270270
}
271271

272-
if (!walker->get_recover)
272+
if (!walker->get_recover) {
273273
for_each_ref(mark_complete, NULL);
274+
commit_list_sort_by_date(&complete);
275+
}
274276

275277
for (i = 0; i < targets; i++) {
276278
if (interpret_target(walker, target[i], &sha1[20 * i])) {

0 commit comments

Comments
 (0)