X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=object-refs.c;h=022e8d841c7f5498b6f008647ed37c430826b443;hb=ed82edc402c271a707da632083f1f4c19155d573;hp=8afa2276fbe9e79bba700b99b1ef345bb6d7f5e8;hpb=64e86c57867593ba0ee77a7b0ff0eb8e9d4d8ed5;p=git.git diff --git a/object-refs.c b/object-refs.c index 8afa2276f..022e8d841 100644 --- a/object-refs.c +++ b/object-refs.c @@ -1,73 +1,20 @@ #include "cache.h" #include "object.h" +#include "decorate.h" int track_object_refs = 0; -static unsigned int refs_hash_size, nr_object_refs; -static struct object_refs **refs_hash; +static struct decoration ref_decorate; -static unsigned int hash_obj(struct object *obj, unsigned int n) +struct object_refs *lookup_object_refs(struct object *base) { - unsigned int hash = *(unsigned int *)obj->sha1; - return hash % n; + return lookup_decoration(&ref_decorate, base); } -static void grow_refs_hash(void) +static void add_object_refs(struct object *obj, struct object_refs *refs) { - int i; - int new_hash_size = (refs_hash_size + 1000) * 3 / 2; - struct object_refs **new_hash; - - new_hash = calloc(new_hash_size, sizeof(struct object_refs *)); - for (i = 0; i < refs_hash_size; i++) { - int j; - struct object_refs *ref = refs_hash[i]; - if (!ref) - continue; - j = hash_obj(ref->base, new_hash_size); - new_hash[j] = ref; - } - free(refs_hash); - refs_hash = new_hash; - 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) -{ - int nr = nr_object_refs + 1; - - if (nr > refs_hash_size * 2 / 3) - grow_refs_hash(); - ref->base = obj; - insert_ref_hash(ref); - nr_object_refs = nr; -} - -struct object_refs *lookup_object_refs(struct object *obj) -{ - int j = hash_obj(obj, refs_hash_size); - struct object_refs *ref; - - while ((ref = refs_hash[j]) != NULL) { - if (ref->base == obj) - break; - j++; - if (j >= refs_hash_size) - j = 0; - } - return ref; + if (add_decoration(&ref_decorate, obj, refs)) + die("object %s tried to add refs twice!", sha1_to_hex(obj->sha1)); } struct object_refs *alloc_object_refs(unsigned count)