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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jan 28, 2021 at 01:20 UTC
8380dcd700e80cd22745bcffb3625f90f943950c
7 files changed
+13
-13
builtin/name-rev.c
+2
-2
@@ -390,9 +390,9 @@ static void name_tips(void)
390
}
391
}
392
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_)
394
{
395
- struct tip_table_entry *table = table_;
395
+ const struct tip_table_entry *table = table_;
396
return &table[ix].oid;
397
}
398
commit-graph.c
+2
-2
@@ -1012,9 +1012,9 @@ static int write_graph_chunk_oids(struct hashfile *f,
1012
return 0;
1013
}
1014
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)
1016
{
1017
- struct commit **commits = table;
1017
+ const struct commit * const *commits = table;
1018
return &commits[index]->object.oid;
1019
}
1020
commit.c
+2
-2
@@ -105,9 +105,9 @@ static timestamp_t parse_commit_date(const char *buf, const char *tail)
105
return parse_timestamp(dateptr, NULL, 10);
106
}
107
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)
109
{
110
- struct commit_graft **commit_graft_table = table;
110
+ const struct commit_graft * const *commit_graft_table = table;
111
return &commit_graft_table[index]->oid;
112
}
113
hash-lookup.c
+1
-1
@@ -50,7 +50,7 @@ static uint32_t take2(const struct object_id *oid, size_t ofs)
50
* The oid of element i (between 0 and nr - 1) should be returned
51
* by "fn(i, table)".
52
*/
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,
54
oid_access_fn fn)
55
{
56
size_t hi = nr;
hash-lookup.h
+2
-2
@@ -1,10 +1,10 @@
1
#ifndef HASH_LOOKUP_H
2
#define HASH_LOOKUP_H
3
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);
5
6
int oid_pos(const struct object_id *oid,
7
- void *table,
7
+ const void *table,
8
size_t nr,
9
oid_access_fn fn);
10
oid-array.c
+2
-2
@@ -22,9 +22,9 @@ void oid_array_sort(struct oid_array *array)
22
array->sorted = 1;
23
}
24
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)
26
{
27
- struct object_id *array = table;
27
+ const struct object_id *array = table;
28
return &array[index];
29
}
30
pack-bitmap-write.c
+2
-2
@@ -610,9 +610,9 @@ static inline void dump_bitmap(struct hashfile *f, struct ewah_bitmap *bitmap)
610
die("Failed to write bitmap index");
611
}
612
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)
614
{
615
- struct pack_idx_entry **index = table;
615
+ const struct pack_idx_entry * const *index = table;
616
return &index[pos]->oid;
617
}
618