Skip to content

Commit

Permalink
walker: avoid quadratic list insertion in mark_complete
Browse files Browse the repository at this point in the history
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 <l.s.r@web.de>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed Aug 25, 2014
1 parent e8d1dfe commit 3bc7a05
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions walker.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ static int mark_complete(const char *path, const unsigned char *sha1, int flag,
struct commit *commit = lookup_commit_reference_gently(sha1, 1);
if (commit) {
commit->object.flags |= COMPLETE;
commit_list_insert_by_date(commit, &complete);
commit_list_insert(commit, &complete);
}
return 0;
}
Expand Down Expand Up @@ -269,8 +269,10 @@ int walker_fetch(struct walker *walker, int targets, char **target,
}
}

if (!walker->get_recover)
if (!walker->get_recover) {
for_each_ref(mark_complete, NULL);
commit_list_sort_by_date(&complete);
}

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

0 comments on commit 3bc7a05

Please sign in to comment.