Skip to content

Commit

Permalink
sha1_name: avoid quadratic list insertion in handle_one_ref
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 d31f3ad commit e8d1dfe
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sha1_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ static int handle_one_ref(const char *path,
}
if (object->type != OBJ_COMMIT)
return 0;
commit_list_insert_by_date((struct commit *)object, list);
commit_list_insert((struct commit *)object, list);
return 0;
}

Expand Down Expand Up @@ -1377,6 +1377,7 @@ static int get_sha1_with_context_1(const char *name,
if (!only_to_die && namelen > 2 && name[1] == '/') {
struct commit_list *list = NULL;
for_each_ref(handle_one_ref, &list);
commit_list_sort_by_date(&list);
return get_sha1_oneline(name + 2, sha1, list);
}
if (namelen < 3 ||
Expand Down

0 comments on commit e8d1dfe

Please sign in to comment.