sha1_name: avoid quadratic list insertion in handle_one_ref
Similar to 16445242 (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>
René Scharfe committed
Aug 21, 2014 at 20:30 UTC
e8d1dfe639f71dc957c30c1eaa82a3ef0010cd8e
1 file changed
+2
-1
sha1_name.c
+2
-1
@@ -835,7 +835,7 @@ static int handle_one_ref(const char *path,
835
}
836
if (object->type != OBJ_COMMIT)
837
return 0;
838
- commit_list_insert_by_date((struct commit *)object, list);
838
+ commit_list_insert((struct commit *)object, list);
839
return 0;
840
}
841
@@ -1377,6 +1377,7 @@ static int get_sha1_with_context_1(const char *name,
1377
if (!only_to_die && namelen > 2 && name[1] == '/') {
1378
struct commit_list *list = NULL;
1379
for_each_ref(handle_one_ref, &list);
1380
+ commit_list_sort_by_date(&list);
1381
return get_sha1_oneline(name + 2, sha1, list);
1382
}
1383
if (namelen < 3 ||