reftable/merged: refactor initialization of iterators

Refactor the initialization of the merged iterator to fit our code style
better. This refactoring prepares the code for a refactoring of how
records are being initialized.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt 2024-02-06 07:35:55 +01:00 committed by Junio C Hamano
parent 59f302ca5a
commit 62d3c8e8c8

View file

@ -19,24 +19,23 @@ license that can be found in the LICENSE file or at
static int merged_iter_init(struct merged_iter *mi)
{
int i = 0;
for (i = 0; i < mi->stack_len; i++) {
struct reftable_record rec = reftable_new_record(mi->typ);
int err = iterator_next(&mi->stack[i], &rec);
if (err < 0) {
return err;
}
for (size_t i = 0; i < mi->stack_len; i++) {
struct pq_entry e = {
.rec = reftable_new_record(mi->typ),
.index = i,
};
int err;
err = iterator_next(&mi->stack[i], &e.rec);
if (err < 0)
return err;
if (err > 0) {
reftable_iterator_destroy(&mi->stack[i]);
reftable_record_release(&rec);
} else {
struct pq_entry e = {
.rec = rec,
.index = i,
};
merged_iter_pqueue_add(&mi->pq, &e);
reftable_record_release(&e.rec);
continue;
}
merged_iter_pqueue_add(&mi->pq, &e);
}
return 0;