Skip to content

Commit a8305bc

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 829231d commit a8305bc

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

reftable/block.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,7 @@ int block_reader_seek(struct block_reader *br, struct block_iter *it,
389389
struct reftable_record rec = reftable_new_record(block_reader_type(br));
390390
struct strbuf key = STRBUF_INIT;
391391
int err = 0;
392-
struct block_iter next = {
393-
.last_key = STRBUF_INIT,
394-
};
392+
struct block_iter next = BLOCK_ITER_INIT;
395393

396394
int i = binsearch(br->restart_count, &restart_key_less, &args);
397395
if (args.error) {

reftable/block.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ struct block_iter {
8686
struct strbuf last_key;
8787
};
8888

89+
#define BLOCK_ITER_INIT { \
90+
.last_key = STRBUF_INIT, \
91+
}
92+
8993
/* initializes a block reader. */
9094
int block_reader_init(struct block_reader *br, struct reftable_block *bl,
9195
uint32_t header_off, uint32_t table_block_size,

reftable/block_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static void test_block_read_write(void)
3232
int i = 0;
3333
int n;
3434
struct block_reader br = { 0 };
35-
struct block_iter it = { .last_key = STRBUF_INIT };
35+
struct block_iter it = BLOCK_ITER_INIT;
3636
int j = 0;
3737
struct strbuf want = STRBUF_INIT;
3838

@@ -87,7 +87,7 @@ static void test_block_read_write(void)
8787
block_iter_close(&it);
8888

8989
for (i = 0; i < N; i++) {
90-
struct block_iter it = { .last_key = STRBUF_INIT };
90+
struct block_iter it = BLOCK_ITER_INIT;
9191
strbuf_reset(&want);
9292
strbuf_addstr(&want, names[i]);
9393

reftable/iter.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ struct indexed_table_ref_iter {
5353
int is_finished;
5454
};
5555

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+
}
6060

6161
void iterator_from_indexed_table_ref_iter(struct reftable_iterator *it,
6262
struct indexed_table_ref_iter *itr);

reftable/reader.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,9 @@ struct table_iter {
224224
struct block_iter bi;
225225
int is_finished;
226226
};
227-
#define TABLE_ITER_INIT \
228-
{ \
229-
.bi = {.last_key = STRBUF_INIT } \
230-
}
227+
#define TABLE_ITER_INIT { \
228+
.bi = BLOCK_ITER_INIT \
229+
}
231230

232231
static void table_iter_copy_from(struct table_iter *dest,
233232
struct table_iter *src)

0 commit comments

Comments
 (0)