@matheusbsbs / matheus-bagliano / commits / 5fdc849965
Fork 0

Fix grow_refs_hash()

Earlier commit 3e4339e6f96e8c4f38a9c6607b98d3e96a2ed783 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>

Linus Torvalds committed Jun 21, 2006 at 11:01 UTC 5fdc8499658969e5ed03184f87cb4290541a0763
1 file changed +14 -16
object-refs.c
+14 -16
@@ -12,6 +12,18 @@ static unsigned int hash_obj(struct object *obj, unsigned int n)
12 return hash % n;
13 }
14
15 +static void insert_ref_hash(struct object_refs *ref, struct object_refs **hash, unsigned int size)
16 +{
17 + int j = hash_obj(ref->base, size);
18 +
19 + while (hash[j]) {
20 + j++;
21 + if (j >= size)
22 + j = 0;
23 + }
24 + hash[j] = ref;
25 +}
26 +
27 static void grow_refs_hash(void)
28 {
29 int i;
@@ -20,30 +32,16 @@ static void grow_refs_hash(void)
32
33 new_hash = calloc(new_hash_size, sizeof(struct object_refs *));
34 for (i = 0; i < refs_hash_size; i++) {
23 - int j;
35 struct object_refs *ref = refs_hash[i];
36 if (!ref)
37 continue;
27 - j = hash_obj(ref->base, new_hash_size);
28 - new_hash[j] = ref;
38 + insert_ref_hash(ref, new_hash, new_hash_size);
39 }
40 free(refs_hash);
41 refs_hash = new_hash;
42 refs_hash_size = new_hash_size;
43 }
44
35 -static void insert_ref_hash(struct object_refs *ref)
36 -{
37 - int j = hash_obj(ref->base, refs_hash_size);
38 -
39 - while (refs_hash[j]) {
40 - j++;
41 - if (j >= refs_hash_size)
42 - j = 0;
43 - }
44 - refs_hash[j] = ref;
45 -}
46 -
45 static void add_object_refs(struct object *obj, struct object_refs *ref)
46 {
47 int nr = nr_object_refs + 1;
@@ -51,7 +49,7 @@ static void add_object_refs(struct object *obj, struct object_refs *ref)
49 if (nr > refs_hash_size * 2 / 3)
50 grow_refs_hash();
51 ref->base = obj;
54 - insert_ref_hash(ref);
52 + insert_ref_hash(ref, refs_hash, refs_hash_size);
53 nr_object_refs = nr;
54 }
55