Skip to content

Commit

Permalink
reftable/block: introduce macro to initialize struct block_iter
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
pks-t authored and gitster committed Dec 11, 2023
1 parent 829231d commit a8305bc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
4 changes: 1 addition & 3 deletions reftable/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,7 @@ int block_reader_seek(struct block_reader *br, struct block_iter *it,
struct reftable_record rec = reftable_new_record(block_reader_type(br));
struct strbuf key = STRBUF_INIT;
int err = 0;
struct block_iter next = {
.last_key = STRBUF_INIT,
};
struct block_iter next = BLOCK_ITER_INIT;

int i = binsearch(br->restart_count, &restart_key_less, &args);
if (args.error) {
Expand Down
4 changes: 4 additions & 0 deletions reftable/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ struct block_iter {
struct strbuf last_key;
};

#define BLOCK_ITER_INIT { \
.last_key = STRBUF_INIT, \
}

/* initializes a block reader. */
int block_reader_init(struct block_reader *br, struct reftable_block *bl,
uint32_t header_off, uint32_t table_block_size,
Expand Down
4 changes: 2 additions & 2 deletions reftable/block_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static void test_block_read_write(void)
int i = 0;
int n;
struct block_reader br = { 0 };
struct block_iter it = { .last_key = STRBUF_INIT };
struct block_iter it = BLOCK_ITER_INIT;
int j = 0;
struct strbuf want = STRBUF_INIT;

Expand Down Expand Up @@ -87,7 +87,7 @@ static void test_block_read_write(void)
block_iter_close(&it);

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

Expand Down
8 changes: 4 additions & 4 deletions reftable/iter.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ struct indexed_table_ref_iter {
int is_finished;
};

#define INDEXED_TABLE_REF_ITER_INIT \
{ \
.cur = { .last_key = STRBUF_INIT }, .oid = STRBUF_INIT, \
}
#define INDEXED_TABLE_REF_ITER_INIT { \
.cur = BLOCK_ITER_INIT, \
.oid = STRBUF_INIT, \
}

void iterator_from_indexed_table_ref_iter(struct reftable_iterator *it,
struct indexed_table_ref_iter *itr);
Expand Down
7 changes: 3 additions & 4 deletions reftable/reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,9 @@ struct table_iter {
struct block_iter bi;
int is_finished;
};
#define TABLE_ITER_INIT \
{ \
.bi = {.last_key = STRBUF_INIT } \
}
#define TABLE_ITER_INIT { \
.bi = BLOCK_ITER_INIT \
}

static void table_iter_copy_from(struct table_iter *dest,
struct table_iter *src)
Expand Down

0 comments on commit a8305bc

Please sign in to comment.