Skip to content

Commit 8380dcd

Browse files
peffgitster
authored andcommitted
oid_pos(): access table through const pointers
When we are looking up an oid in an array, we obviously don't need to write to the array. Let's mark it as const in the function interfaces, as well as in the local variables we use to derference the void pointer (note a few cases use pointers-to-pointers, so we mark everything const). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 45ee13b commit 8380dcd

File tree

7 files changed

+13
-13
lines changed

7 files changed

+13
-13
lines changed

builtin/name-rev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,9 @@ static void name_tips(void)
390390
}
391391
}
392392

393-
static const struct object_id *nth_tip_table_ent(size_t ix, void *table_)
393+
static const struct object_id *nth_tip_table_ent(size_t ix, const void *table_)
394394
{
395-
struct tip_table_entry *table = table_;
395+
const struct tip_table_entry *table = table_;
396396
return &table[ix].oid;
397397
}
398398

commit-graph.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,9 +1012,9 @@ static int write_graph_chunk_oids(struct hashfile *f,
10121012
return 0;
10131013
}
10141014

1015-
static const struct object_id *commit_to_oid(size_t index, void *table)
1015+
static const struct object_id *commit_to_oid(size_t index, const void *table)
10161016
{
1017-
struct commit **commits = table;
1017+
const struct commit * const *commits = table;
10181018
return &commits[index]->object.oid;
10191019
}
10201020

commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ static timestamp_t parse_commit_date(const char *buf, const char *tail)
105105
return parse_timestamp(dateptr, NULL, 10);
106106
}
107107

108-
static const struct object_id *commit_graft_oid_access(size_t index, void *table)
108+
static const struct object_id *commit_graft_oid_access(size_t index, const void *table)
109109
{
110-
struct commit_graft **commit_graft_table = table;
110+
const struct commit_graft * const *commit_graft_table = table;
111111
return &commit_graft_table[index]->oid;
112112
}
113113

hash-lookup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static uint32_t take2(const struct object_id *oid, size_t ofs)
5050
* The oid of element i (between 0 and nr - 1) should be returned
5151
* by "fn(i, table)".
5252
*/
53-
int oid_pos(const struct object_id *oid, void *table, size_t nr,
53+
int oid_pos(const struct object_id *oid, const void *table, size_t nr,
5454
oid_access_fn fn)
5555
{
5656
size_t hi = nr;

hash-lookup.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#ifndef HASH_LOOKUP_H
22
#define HASH_LOOKUP_H
33

4-
typedef const struct object_id *oid_access_fn(size_t index, void *table);
4+
typedef const struct object_id *oid_access_fn(size_t index, const void *table);
55

66
int oid_pos(const struct object_id *oid,
7-
void *table,
7+
const void *table,
88
size_t nr,
99
oid_access_fn fn);
1010

oid-array.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ void oid_array_sort(struct oid_array *array)
2222
array->sorted = 1;
2323
}
2424

25-
static const struct object_id *oid_access(size_t index, void *table)
25+
static const struct object_id *oid_access(size_t index, const void *table)
2626
{
27-
struct object_id *array = table;
27+
const struct object_id *array = table;
2828
return &array[index];
2929
}
3030

pack-bitmap-write.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,9 @@ static inline void dump_bitmap(struct hashfile *f, struct ewah_bitmap *bitmap)
610610
die("Failed to write bitmap index");
611611
}
612612

613-
static const struct object_id *oid_access(size_t pos, void *table)
613+
static const struct object_id *oid_access(size_t pos, const void *table)
614614
{
615-
struct pack_idx_entry **index = table;
615+
const struct pack_idx_entry * const *index = table;
616616
return &index[pos]->oid;
617617
}
618618

0 commit comments

Comments
 (0)