@matheusbsbs / matheus-bagliano / commits / 54988bdad7
Fork 0

decorate: allow const objects to be decorated

We don't actually modify the struct object, so there is no reason not to accept const versions (and this allows other callsites, like the next patch, to use the decoration machinery). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Aug 20, 2008 at 13:55 UTC 54988bdad7dc3f09e40752221c144bf470d73aa7
2 files changed +9 -8
decorate.c
+6 -5
@@ -6,13 +6,13 @@
6 #include "object.h"
7 #include "decorate.h"
8
9 -static unsigned int hash_obj(struct object *obj, unsigned int n)
9 +static unsigned int hash_obj(const struct object *obj, unsigned int n)
10 {
11 unsigned int hash = *(unsigned int *)obj->sha1;
12 return hash % n;
13 }
14
15 -static void *insert_decoration(struct decoration *n, struct object *base, void *decoration)
15 +static void *insert_decoration(struct decoration *n, const struct object *base, void *decoration)
16 {
17 int size = n->size;
18 struct object_decoration *hash = n->hash;
@@ -44,7 +44,7 @@ static void grow_decoration(struct decoration *n)
44 n->nr = 0;
45
46 for (i = 0; i < old_size; i++) {
47 - struct object *base = old_hash[i].base;
47 + const struct object *base = old_hash[i].base;
48 void *decoration = old_hash[i].decoration;
49
50 if (!base)
@@ -55,7 +55,8 @@ static void grow_decoration(struct decoration *n)
55 }
56
57 /* Add a decoration pointer, return any old one */
58 -void *add_decoration(struct decoration *n, struct object *obj, void *decoration)
58 +void *add_decoration(struct decoration *n, const struct object *obj,
59 + void *decoration)
60 {
61 int nr = n->nr + 1;
62
@@ -65,7 +66,7 @@ void *add_decoration(struct decoration *n, struct object *obj, void *decoration)
66 }
67
68 /* Lookup a decoration pointer */
68 -void *lookup_decoration(struct decoration *n, struct object *obj)
69 +void *lookup_decoration(struct decoration *n, const struct object *obj)
70 {
71 int j;
72
decorate.h
+3 -3
@@ -2,7 +2,7 @@
2 #define DECORATE_H
3
4 struct object_decoration {
5 - struct object *base;
5 + const struct object *base;
6 void *decoration;
7 };
8
@@ -12,7 +12,7 @@ struct decoration {
12 struct object_decoration *hash;
13 };
14
15 -extern void *add_decoration(struct decoration *n, struct object *obj, void *decoration);
16 -extern void *lookup_decoration(struct decoration *n, struct object *obj);
15 +extern void *add_decoration(struct decoration *n, const struct object *obj, void *decoration);
16 +extern void *lookup_decoration(struct decoration *n, const struct object *obj);
17
18 #endif