Don't sort ref_list too early
get_ref_dir is called recursively for subdirectories, which means that we were calling sort_ref_list for each directory of refs instead of once for all the refs. This is a massive wast of processing, so now just call sort_ref_list on the result of the top-level get_ref_dir, so that the sort is only done once. In the common case of only a few different directories of refs the difference isn't very noticable, but it becomes very noticeable when you have a large number of direcotries containing refs (e.g. as created by Gerrit). Reported by Martin Fick. Signed-off-by: Julian Phillips <julian@quantumfyre.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Julian Phillips committed
Sep 27, 2011 at 01:00 UTC
b4f223c6367bb7aefa00c746c808f5afa7b85331
1 file changed
+3
-1
refs.c
+3
-1
@@ -319,7 +319,7 @@ static struct ref_list *get_ref_dir(const char *submodule, const char *base,
319
free(ref);
320
closedir(dir);
321
}
322
- return sort_ref_list(list);
322
+ return list;
323
}
324
325
struct warn_if_dangling_data {
@@ -361,11 +361,13 @@ static struct ref_list *get_loose_refs(const char *submodule)
361
if (submodule) {
362
free_ref_list(submodule_refs.loose);
363
submodule_refs.loose = get_ref_dir(submodule, "refs", NULL);
364
+ submodule_refs.loose = sort_ref_list(submodule_refs.loose);
365
return submodule_refs.loose;
366
}
367
368
if (!cached_refs.did_loose) {
369
cached_refs.loose = get_ref_dir(NULL, "refs", NULL);
370
+ cached_refs.loose = sort_ref_list(cached_refs.loose);
371
cached_refs.did_loose = 1;
372
}
373
return cached_refs.loose;