]> git.ipfire.org Git - thirdparty/git.git/commitdiff
prune_remote(): sort delete_refs_list references en masse
authorMichael Haggerty <mhagger@alum.mit.edu>
Tue, 25 Nov 2014 08:02:31 +0000 (09:02 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 25 Nov 2014 18:09:49 +0000 (10:09 -0800)
Inserting items into a list in sorted order is O(N^2) whereas
appending them unsorted and then sorting the list all at once is
O(N lg N).

string_list_insert() also removes duplicates, and this change loses
that functionality. But the strings in this list, which ultimately
come from a for_each_ref() iteration, cannot contain duplicates.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/remote.c

index d5a5a1663b82c78a68fc0c74770a0db351b4ca9c..7d5c8d2074ba503601f45e3a0100c7f5326340cd 100644 (file)
@@ -1341,8 +1341,9 @@ static int prune_remote(const char *remote, int dry_run)
                const char *refname = states.stale.items[i].util;
 
                delete_refs[i] = refname;
-               string_list_insert(&delete_refs_list, refname);
+               string_list_append(&delete_refs_list, refname);
        }
+       sort_string_list(&delete_refs_list);
 
        if (!dry_run) {
                struct strbuf err = STRBUF_INIT;