2 * decorate.c - decorate a git object with some arbitrary
9 static unsigned int hash_obj(struct object
*obj
, unsigned int n
)
11 unsigned int hash
= *(unsigned int *)obj
->sha1
;
15 static void *insert_decoration(struct decoration
*n
, struct object
*base
, void *decoration
)
18 struct object_decoration
*hash
= n
->hash
;
19 int j
= hash_obj(base
, size
);
21 while (hash
[j
].base
) {
22 if (hash
[j
].base
== base
) {
23 void *old
= hash
[j
].decoration
;
24 hash
[j
].decoration
= decoration
;
31 hash
[j
].decoration
= decoration
;
36 static void grow_decoration(struct decoration
*n
)
39 int old_size
= n
->size
;
40 struct object_decoration
*old_hash
= n
->hash
;
42 n
->size
= (old_size
+ 1000) * 3 / 2;
43 n
->hash
= xcalloc(n
->size
, sizeof(struct object_decoration
));
46 for (i
= 0; i
< old_size
; i
++) {
47 struct object
*base
= old_hash
[i
].base
;
48 void *decoration
= old_hash
[i
].decoration
;
52 insert_decoration(n
, base
, decoration
);
57 /* Add a decoration pointer, return any old one */
58 void *add_decoration(struct decoration
*n
, struct object
*obj
, void *decoration
)
62 if (nr
> n
->size
* 2 / 3)
64 return insert_decoration(n
, obj
, decoration
);
67 /* Lookup a decoration pointer */
68 void *lookup_decoration(struct decoration
*n
, struct object
*obj
)
72 /* nothing to lookup */
75 j
= hash_obj(obj
, n
->size
);
77 struct object_decoration
*ref
= n
->hash
+ j
;
79 return ref
->decoration
;