]> git.ipfire.org Git - thirdparty/git.git/commitdiff
oid_pos(): access table through const pointers
authorJeff King <peff@peff.net>
Thu, 28 Jan 2021 06:20:23 +0000 (01:20 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 28 Jan 2021 20:03:26 +0000 (12:03 -0800)
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>
builtin/name-rev.c
commit-graph.c
commit.c
hash-lookup.c
hash-lookup.h
oid-array.c
pack-bitmap-write.c

index 27138fdce4718ad0395b512d763b00c5c2df72d5..b221d300147fcdc1966b6415e1a1549a149d10ac 100644 (file)
@@ -390,9 +390,9 @@ static void name_tips(void)
        }
 }
 
-static const struct object_id *nth_tip_table_ent(size_t ix, void *table_)
+static const struct object_id *nth_tip_table_ent(size_t ix, const void *table_)
 {
-       struct tip_table_entry *table = table_;
+       const struct tip_table_entry *table = table_;
        return &table[ix].oid;
 }
 
index 248f1efb73ea942d45054837088e2def79daf02b..b09fce5f573f38b703dbcd22ebe72c3d7e3007ba 100644 (file)
@@ -1012,9 +1012,9 @@ static int write_graph_chunk_oids(struct hashfile *f,
        return 0;
 }
 
-static const struct object_id *commit_to_oid(size_t index, void *table)
+static const struct object_id *commit_to_oid(size_t index, const void *table)
 {
-       struct commit **commits = table;
+       const struct commit * const *commits = table;
        return &commits[index]->object.oid;
 }
 
index 39eab5b36bce9916ff94a935d2fe2cfa1baa1df9..fd2831dad3243f32f5bae472f2af6ad15019c67d 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -105,9 +105,9 @@ static timestamp_t parse_commit_date(const char *buf, const char *tail)
        return parse_timestamp(dateptr, NULL, 10);
 }
 
-static const struct object_id *commit_graft_oid_access(size_t index, void *table)
+static const struct object_id *commit_graft_oid_access(size_t index, const void *table)
 {
-       struct commit_graft **commit_graft_table = table;
+       const struct commit_graft * const *commit_graft_table = table;
        return &commit_graft_table[index]->oid;
 }
 
index d15bb345749470b0aac9e6c3d4b1f36b78d6bdee..b98ed5e11e8a3af02a99b6d2a977cc804a122414 100644 (file)
@@ -50,7 +50,7 @@ static uint32_t take2(const struct object_id *oid, size_t ofs)
  * The oid of element i (between 0 and nr - 1) should be returned
  * by "fn(i, table)".
  */
-int oid_pos(const struct object_id *oid, void *table, size_t nr,
+int oid_pos(const struct object_id *oid, const void *table, size_t nr,
            oid_access_fn fn)
 {
        size_t hi = nr;
index 7b3ecad1f0331bc9fbc1562a67c95729029cdaca..dbd71ebaf73044ea7d10d6686d6b193b32be6863 100644 (file)
@@ -1,10 +1,10 @@
 #ifndef HASH_LOOKUP_H
 #define HASH_LOOKUP_H
 
-typedef const struct object_id *oid_access_fn(size_t index, void *table);
+typedef const struct object_id *oid_access_fn(size_t index, const void *table);
 
 int oid_pos(const struct object_id *oid,
-           void *table,
+           const void *table,
            size_t nr,
            oid_access_fn fn);
 
index a19235afbf8408734b38eddea7ef5bf3fe29e673..73ba76e9e9a223306a03c3d04123c0c4af4aeda2 100644 (file)
@@ -22,9 +22,9 @@ void oid_array_sort(struct oid_array *array)
        array->sorted = 1;
 }
 
-static const struct object_id *oid_access(size_t index, void *table)
+static const struct object_id *oid_access(size_t index, const void *table)
 {
-       struct object_id *array = table;
+       const struct object_id *array = table;
        return &array[index];
 }
 
index f21259dfc82fc556e698524e24193d2b584d5149..88d9e696a546a8db20d3ff7147a1bb15f8651d36 100644 (file)
@@ -610,9 +610,9 @@ static inline void dump_bitmap(struct hashfile *f, struct ewah_bitmap *bitmap)
                die("Failed to write bitmap index");
 }
 
-static const struct object_id *oid_access(size_t pos, void *table)
+static const struct object_id *oid_access(size_t pos, const void *table)
 {
-       struct pack_idx_entry **index = table;
+       const struct pack_idx_entry * const *index = table;
        return &index[pos]->oid;
 }