reftable/block: introduce macro to initialize `struct block_iter`
There are a bunch of locations where we initialize members of `struct block_iter`, which makes it harder than necessary to expand this struct to have additional members. Unify the logic via a new `BLOCK_ITER_INIT` macro that initializes all members. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Dec 11, 2023 at 10:08 UTC
a8305bc6d8eb55cf52264964c8fc0289b72f2fd8
5 files changed
+14
-13
reftable/block.c
+1
-3
@@ -389,9 +389,7 @@ int block_reader_seek(struct block_reader *br, struct block_iter *it,
389
struct reftable_record rec = reftable_new_record(block_reader_type(br));
390
struct strbuf key = STRBUF_INIT;
391
int err = 0;
392
- struct block_iter next = {
393
- .last_key = STRBUF_INIT,
394
- };
392
+ struct block_iter next = BLOCK_ITER_INIT;
393
394
int i = binsearch(br->restart_count, &restart_key_less, &args);
395
if (args.error) {
reftable/block.h
+4
@@ -86,6 +86,10 @@ struct block_iter {
86
struct strbuf last_key;
87
};
88
89
+#define BLOCK_ITER_INIT { \
90
+ .last_key = STRBUF_INIT, \
91
+}
92
+
93
/* initializes a block reader. */
94
int block_reader_init(struct block_reader *br, struct reftable_block *bl,
95
uint32_t header_off, uint32_t table_block_size,
reftable/block_test.c
+2
-2
@@ -32,7 +32,7 @@ static void test_block_read_write(void)
32
int i = 0;
33
int n;
34
struct block_reader br = { 0 };
35
- struct block_iter it = { .last_key = STRBUF_INIT };
35
+ struct block_iter it = BLOCK_ITER_INIT;
36
int j = 0;
37
struct strbuf want = STRBUF_INIT;
38
@@ -87,7 +87,7 @@ static void test_block_read_write(void)
87
block_iter_close(&it);
88
89
for (i = 0; i < N; i++) {
90
- struct block_iter it = { .last_key = STRBUF_INIT };
90
+ struct block_iter it = BLOCK_ITER_INIT;
91
strbuf_reset(&want);
92
strbuf_addstr(&want, names[i]);
93
reftable/iter.h
+4
-4
@@ -53,10 +53,10 @@ struct indexed_table_ref_iter {
53
int is_finished;
54
};
55
56
-#define INDEXED_TABLE_REF_ITER_INIT \
57
- { \
58
- .cur = { .last_key = STRBUF_INIT }, .oid = STRBUF_INIT, \
59
- }
56
+#define INDEXED_TABLE_REF_ITER_INIT { \
57
+ .cur = BLOCK_ITER_INIT, \
58
+ .oid = STRBUF_INIT, \
59
+}
60
61
void iterator_from_indexed_table_ref_iter(struct reftable_iterator *it,
62
struct indexed_table_ref_iter *itr);
reftable/reader.c
+3
-4
@@ -224,10 +224,9 @@ struct table_iter {
224
struct block_iter bi;
225
int is_finished;
226
};
227
-#define TABLE_ITER_INIT \
228
- { \
229
- .bi = {.last_key = STRBUF_INIT } \
230
- }
227
+#define TABLE_ITER_INIT { \
228
+ .bi = BLOCK_ITER_INIT \
229
+}
230
231
static void table_iter_copy_from(struct table_iter *dest,
232
struct table_iter *src)