mirror of
https://github.com/git/git
synced 2024-08-28 20:20:07 +00:00
Fix grow_refs_hash()
Earlier commit 3e4339e6f9
had a
thinko that did not check for collisions while repopulating the
objects in the new hash table.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
86f660b1f1
commit
5fdc849965
|
@ -12,6 +12,18 @@ static unsigned int hash_obj(struct object *obj, unsigned int n)
|
||||||
return hash % n;
|
return hash % n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void insert_ref_hash(struct object_refs *ref, struct object_refs **hash, unsigned int size)
|
||||||
|
{
|
||||||
|
int j = hash_obj(ref->base, size);
|
||||||
|
|
||||||
|
while (hash[j]) {
|
||||||
|
j++;
|
||||||
|
if (j >= size)
|
||||||
|
j = 0;
|
||||||
|
}
|
||||||
|
hash[j] = ref;
|
||||||
|
}
|
||||||
|
|
||||||
static void grow_refs_hash(void)
|
static void grow_refs_hash(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -20,30 +32,16 @@ static void grow_refs_hash(void)
|
||||||
|
|
||||||
new_hash = calloc(new_hash_size, sizeof(struct object_refs *));
|
new_hash = calloc(new_hash_size, sizeof(struct object_refs *));
|
||||||
for (i = 0; i < refs_hash_size; i++) {
|
for (i = 0; i < refs_hash_size; i++) {
|
||||||
int j;
|
|
||||||
struct object_refs *ref = refs_hash[i];
|
struct object_refs *ref = refs_hash[i];
|
||||||
if (!ref)
|
if (!ref)
|
||||||
continue;
|
continue;
|
||||||
j = hash_obj(ref->base, new_hash_size);
|
insert_ref_hash(ref, new_hash, new_hash_size);
|
||||||
new_hash[j] = ref;
|
|
||||||
}
|
}
|
||||||
free(refs_hash);
|
free(refs_hash);
|
||||||
refs_hash = new_hash;
|
refs_hash = new_hash;
|
||||||
refs_hash_size = new_hash_size;
|
refs_hash_size = new_hash_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void insert_ref_hash(struct object_refs *ref)
|
|
||||||
{
|
|
||||||
int j = hash_obj(ref->base, refs_hash_size);
|
|
||||||
|
|
||||||
while (refs_hash[j]) {
|
|
||||||
j++;
|
|
||||||
if (j >= refs_hash_size)
|
|
||||||
j = 0;
|
|
||||||
}
|
|
||||||
refs_hash[j] = ref;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void add_object_refs(struct object *obj, struct object_refs *ref)
|
static void add_object_refs(struct object *obj, struct object_refs *ref)
|
||||||
{
|
{
|
||||||
int nr = nr_object_refs + 1;
|
int nr = nr_object_refs + 1;
|
||||||
|
@ -51,7 +49,7 @@ static void add_object_refs(struct object *obj, struct object_refs *ref)
|
||||||
if (nr > refs_hash_size * 2 / 3)
|
if (nr > refs_hash_size * 2 / 3)
|
||||||
grow_refs_hash();
|
grow_refs_hash();
|
||||||
ref->base = obj;
|
ref->base = obj;
|
||||||
insert_ref_hash(ref);
|
insert_ref_hash(ref, refs_hash, refs_hash_size);
|
||||||
nr_object_refs = nr;
|
nr_object_refs = nr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue