summaryrefslogtreecommitdiff
path: root/fetch-pack.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-04-25 16:41:16 +0900
committerJunio C Hamano <gitster@pobox.com>2019-04-25 16:41:16 +0900
commitabd7ccdd4ddcc2d2ce1d51943051c071902b159a (patch)
treead7151949f443377e6845f3e0223363b31d1ea63 /fetch-pack.c
parent8baf40b5b463bc6e52b0ef5c5c3d495bb0a920b3 (diff)
parentb7643009123216792aa158d3b2ca64a79adc01e2 (diff)
downloadgit-abd7ccdd4ddcc2d2ce1d51943051c071902b159a.tar.gz
Merge branch 'jt/fetch-pack-wanted-refs-optim'
Performance fix around "git fetch" that grabs many refs. * jt/fetch-pack-wanted-refs-optim: fetch-pack: binary search when storing wanted-refs
Diffstat (limited to 'fetch-pack.c')
-rw-r--r--fetch-pack.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/fetch-pack.c b/fetch-pack.c
index 8d67d4e362..01cdee01b4 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -1298,6 +1298,11 @@ static void receive_shallow_info(struct fetch_pack_args *args,
}
}
+static int cmp_name_ref(const void *name, const void *ref)
+{
+ return strcmp(name, (*(struct ref **)ref)->name);
+}
+
static void receive_wanted_refs(struct packet_reader *reader,
struct ref **sought, int nr_sought)
{
@@ -1305,20 +1310,16 @@ static void receive_wanted_refs(struct packet_reader *reader,
while (packet_reader_read(reader) == PACKET_READ_NORMAL) {
struct object_id oid;
const char *end;
- int i;
+ struct ref **found;
if (parse_oid_hex(reader->line, &oid, &end) || *end++ != ' ')
die(_("expected wanted-ref, got '%s'"), reader->line);
- for (i = 0; i < nr_sought; i++) {
- if (!strcmp(end, sought[i]->name)) {
- oidcpy(&sought[i]->old_oid, &oid);
- break;
- }
- }
-
- if (i == nr_sought)
+ found = bsearch(end, sought, nr_sought, sizeof(*sought),
+ cmp_name_ref);
+ if (!found)
die(_("unexpected wanted-ref: '%s'"), reader->line);
+ oidcpy(&(*found)->old_oid, &oid);
}
if (reader->status != PACKET_READ_DELIM)