Skip to content

Commit 54988bd

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e276c26 commit 54988bd

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

decorate.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
#include "object.h"
77
#include "decorate.h"
88

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)
1010
{
1111
unsigned int hash = *(unsigned int *)obj->sha1;
1212
return hash % n;
1313
}
1414

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)
1616
{
1717
int size = n->size;
1818
struct object_decoration *hash = n->hash;
@@ -44,7 +44,7 @@ static void grow_decoration(struct decoration *n)
4444
n->nr = 0;
4545

4646
for (i = 0; i < old_size; i++) {
47-
struct object *base = old_hash[i].base;
47+
const struct object *base = old_hash[i].base;
4848
void *decoration = old_hash[i].decoration;
4949

5050
if (!base)
@@ -55,7 +55,8 @@ static void grow_decoration(struct decoration *n)
5555
}
5656

5757
/* 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)
5960
{
6061
int nr = n->nr + 1;
6162

@@ -65,7 +66,7 @@ void *add_decoration(struct decoration *n, struct object *obj, void *decoration)
6566
}
6667

6768
/* 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)
6970
{
7071
int j;
7172

decorate.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define DECORATE_H
33

44
struct object_decoration {
5-
struct object *base;
5+
const struct object *base;
66
void *decoration;
77
};
88

@@ -12,7 +12,7 @@ struct decoration {
1212
struct object_decoration *hash;
1313
};
1414

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);
1717

1818
#endif

0 commit comments

Comments
 (0)