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>
This commit is contained in:
parent
829231dc20
commit
a8305bc6d8
@ -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 reftable_record rec = reftable_new_record(block_reader_type(br));
|
||||||
struct strbuf key = STRBUF_INIT;
|
struct strbuf key = STRBUF_INIT;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
struct block_iter next = {
|
struct block_iter next = BLOCK_ITER_INIT;
|
||||||
.last_key = STRBUF_INIT,
|
|
||||||
};
|
|
||||||
|
|
||||||
int i = binsearch(br->restart_count, &restart_key_less, &args);
|
int i = binsearch(br->restart_count, &restart_key_less, &args);
|
||||||
if (args.error) {
|
if (args.error) {
|
||||||
|
@ -86,6 +86,10 @@ struct block_iter {
|
|||||||
struct strbuf last_key;
|
struct strbuf last_key;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define BLOCK_ITER_INIT { \
|
||||||
|
.last_key = STRBUF_INIT, \
|
||||||
|
}
|
||||||
|
|
||||||
/* initializes a block reader. */
|
/* initializes a block reader. */
|
||||||
int block_reader_init(struct block_reader *br, struct reftable_block *bl,
|
int block_reader_init(struct block_reader *br, struct reftable_block *bl,
|
||||||
uint32_t header_off, uint32_t table_block_size,
|
uint32_t header_off, uint32_t table_block_size,
|
||||||
|
@ -32,7 +32,7 @@ static void test_block_read_write(void)
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
int n;
|
int n;
|
||||||
struct block_reader br = { 0 };
|
struct block_reader br = { 0 };
|
||||||
struct block_iter it = { .last_key = STRBUF_INIT };
|
struct block_iter it = BLOCK_ITER_INIT;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
struct strbuf want = STRBUF_INIT;
|
struct strbuf want = STRBUF_INIT;
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ static void test_block_read_write(void)
|
|||||||
block_iter_close(&it);
|
block_iter_close(&it);
|
||||||
|
|
||||||
for (i = 0; i < N; i++) {
|
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_reset(&want);
|
||||||
strbuf_addstr(&want, names[i]);
|
strbuf_addstr(&want, names[i]);
|
||||||
|
|
||||||
|
@ -53,10 +53,10 @@ struct indexed_table_ref_iter {
|
|||||||
int is_finished;
|
int is_finished;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define INDEXED_TABLE_REF_ITER_INIT \
|
#define INDEXED_TABLE_REF_ITER_INIT { \
|
||||||
{ \
|
.cur = BLOCK_ITER_INIT, \
|
||||||
.cur = { .last_key = STRBUF_INIT }, .oid = STRBUF_INIT, \
|
.oid = STRBUF_INIT, \
|
||||||
}
|
}
|
||||||
|
|
||||||
void iterator_from_indexed_table_ref_iter(struct reftable_iterator *it,
|
void iterator_from_indexed_table_ref_iter(struct reftable_iterator *it,
|
||||||
struct indexed_table_ref_iter *itr);
|
struct indexed_table_ref_iter *itr);
|
||||||
|
@ -224,10 +224,9 @@ struct table_iter {
|
|||||||
struct block_iter bi;
|
struct block_iter bi;
|
||||||
int is_finished;
|
int is_finished;
|
||||||
};
|
};
|
||||||
#define TABLE_ITER_INIT \
|
#define TABLE_ITER_INIT { \
|
||||||
{ \
|
.bi = BLOCK_ITER_INIT \
|
||||||
.bi = {.last_key = STRBUF_INIT } \
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static void table_iter_copy_from(struct table_iter *dest,
|
static void table_iter_copy_from(struct table_iter *dest,
|
||||||
struct table_iter *src)
|
struct table_iter *src)
|
||||||
|
Loading…
Reference in New Issue
Block a user