sha1_name: use bsearch_pack() for abbreviations
When computing abbreviation lengths for an object ID against a single packfile, the method find_abbrev_len_for_pack() currently implements binary search. This is one of several implementations. One issue with this implementation is that it ignores the fanout table in the pack- index. Translate this binary search to use the existing bsearch_pack() method that correctly uses a fanout table. Due to the use of the fanout table, the abbreviation computation is slightly faster than before. For a fully-repacked copy of the Linux repo, the following 'git log' commands improved: * git log --oneline --parents --raw Before: 59.2s After: 56.9s Rel %: -3.8% * git log --oneline --parents Before: 6.48s After: 5.91s Rel %: -8.9% Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
3d475f46a8
commit
0aaf05b3bd
24
sha1_name.c
24
sha1_name.c
@ -512,32 +512,16 @@ static void find_abbrev_len_for_pack(struct packed_git *p,
|
|||||||
struct min_abbrev_data *mad)
|
struct min_abbrev_data *mad)
|
||||||
{
|
{
|
||||||
int match = 0;
|
int match = 0;
|
||||||
uint32_t num, last, first = 0;
|
uint32_t num, first = 0;
|
||||||
struct object_id oid;
|
struct object_id oid;
|
||||||
|
const struct object_id *mad_oid;
|
||||||
|
|
||||||
if (open_pack_index(p) || !p->num_objects)
|
if (open_pack_index(p) || !p->num_objects)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
num = p->num_objects;
|
num = p->num_objects;
|
||||||
last = num;
|
mad_oid = mad->oid;
|
||||||
while (first < last) {
|
match = bsearch_pack(mad_oid, p, &first);
|
||||||
uint32_t mid = first + (last - first) / 2;
|
|
||||||
const unsigned char *current;
|
|
||||||
int cmp;
|
|
||||||
|
|
||||||
current = nth_packed_object_sha1(p, mid);
|
|
||||||
cmp = hashcmp(mad->oid->hash, current);
|
|
||||||
if (!cmp) {
|
|
||||||
match = 1;
|
|
||||||
first = mid;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (cmp > 0) {
|
|
||||||
first = mid + 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
last = mid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* first is now the position in the packfile where we would insert
|
* first is now the position in the packfile where we would insert
|
||||||
|
Reference in New Issue
Block a user