2 * decorate.c - decorate a git object with some arbitrary
9 static unsigned int hash_obj(const struct object
*obj
, unsigned int n
)
13 memcpy(&hash
, obj
->sha1
, sizeof(unsigned int));
17 static void *insert_decoration(struct decoration
*n
, const struct object
*base
, void *decoration
)
20 struct object_decoration
*hash
= n
->hash
;
21 int j
= hash_obj(base
, size
);
23 while (hash
[j
].base
) {
24 if (hash
[j
].base
== base
) {
25 void *old
= hash
[j
].decoration
;
26 hash
[j
].decoration
= decoration
;
33 hash
[j
].decoration
= decoration
;
38 static void grow_decoration(struct decoration
*n
)
41 int old_size
= n
->size
;
42 struct object_decoration
*old_hash
= n
->hash
;
44 n
->size
= (old_size
+ 1000) * 3 / 2;
45 n
->hash
= xcalloc(n
->size
, sizeof(struct object_decoration
));
48 for (i
= 0; i
< old_size
; i
++) {
49 const struct object
*base
= old_hash
[i
].base
;
50 void *decoration
= old_hash
[i
].decoration
;
54 insert_decoration(n
, base
, decoration
);
59 /* Add a decoration pointer, return any old one */
60 void *add_decoration(struct decoration
*n
, const struct object
*obj
,
65 if (nr
> n
->size
* 2 / 3)
67 return insert_decoration(n
, obj
, decoration
);
70 /* Lookup a decoration pointer */
71 void *lookup_decoration(struct decoration
*n
, const struct object
*obj
)
75 /* nothing to lookup */
78 j
= hash_obj(obj
, n
->size
);
80 struct object_decoration
*ref
= n
->hash
+ j
;
82 return ref
->decoration
;