Skip to content

Commit e8d1dfe

Browse files
rscharfegitster
authored andcommitted
sha1_name: avoid quadratic list insertion in handle_one_ref
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 d31f3ad commit e8d1dfe

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

sha1_name.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ static int handle_one_ref(const char *path,
835835
}
836836
if (object->type != OBJ_COMMIT)
837837
return 0;
838-
commit_list_insert_by_date((struct commit *)object, list);
838+
commit_list_insert((struct commit *)object, list);
839839
return 0;
840840
}
841841

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

0 commit comments

Comments
 (0)