From: Michael Haggerty <mhagger@alum.mit.edu>
To: Junio C Hamano <gitster@pobox.com>
Cc: Stefan Beller <sbeller@google.com>,
Jonathan Nieder <jrnieder@gmail.com>,
Ronnie Sahlberg <sahlberg@google.com>,
git@vger.kernel.org, Michael Haggerty <mhagger@alum.mit.edu>
Subject: [PATCH v2 3/7] prune_remote(): sort delete_refs_list references en masse
Date: Tue, 25 Nov 2014 09:02:31 +0100 [thread overview]
Message-ID: <1416902555-10748-4-git-send-email-mhagger@alum.mit.edu> (raw)
In-Reply-To: <1416902555-10748-1-git-send-email-mhagger@alum.mit.edu>
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>
---
builtin/remote.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/builtin/remote.c b/builtin/remote.c
index d5a5a16..7d5c8d2 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -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;
--
2.1.3
next prev parent reply other threads:[~2014-11-25 8:03 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-25 8:02 [PATCH v2 0/7] repack_without_refs(): convert to string_list Michael Haggerty
2014-11-25 8:02 ` [PATCH v2 1/7] prune_remote(): exit early if there are no stale references Michael Haggerty
2014-11-25 18:09 ` Junio C Hamano
2014-11-25 8:02 ` [PATCH v2 2/7] prune_remote(): initialize both delete_refs lists in a single loop Michael Haggerty
2014-11-25 8:02 ` Michael Haggerty [this message]
2014-11-25 8:02 ` [PATCH v2 4/7] repack_without_refs(): make the refnames argument a string_list Michael Haggerty
2014-11-25 8:02 ` [PATCH v2 5/7] prune_remote(): rename local variable Michael Haggerty
2014-11-25 8:02 ` [PATCH v2 6/7] prune_remote(): iterate using for_each_string_list_item() Michael Haggerty
2014-11-25 8:02 ` [PATCH v2 7/7] Rename sort_string_list() to string_list_sort() Michael Haggerty
2014-11-25 18:17 ` Junio C Hamano
2014-11-26 1:15 ` [PATCH v2 0/7] repack_without_refs(): convert to string_list Stefan Beller
2014-11-26 17:55 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1416902555-10748-4-git-send-email-mhagger@alum.mit.edu \
--to=mhagger@alum.mit.edu \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=sahlberg@google.com \
--cc=sbeller@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).