Skip to content

Commit 701713a

Browse files
pks-tgitster
authored andcommitted
reftable/merged: simplify indices for subiterators
When seeking on a merged table, we perform the seek for each of the subiterators. If the subiterator has the desired record we add it to the priority queue, otherwise we skip it and don't add it to the stack of subiterators hosted by the merged table. The consequence of this is that the index of the subiterator in the merged table does not necessarily correspond to the index of it in the merged iterator. Next to being potentially confusing, it also means that we won't easily be able to re-seek the merged iterator because we have no clear connection between both of the data structures. Refactor the code so that the index stays the same in both structures. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e08f49a commit 701713a

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

reftable/merged.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static void merged_iter_init(struct merged_iter *mi,
3737
mi->advance_index = -1;
3838
mi->suppress_deletions = mt->suppress_deletions;
3939
REFTABLE_CALLOC_ARRAY(mi->subiters, mt->stack_len);
40+
mi->stack_len = mt->stack_len;
4041
}
4142

4243
static void merged_iter_close(void *p)
@@ -236,21 +237,19 @@ static int merged_table_seek_record(struct reftable_merged_table *mt,
236237
merged_iter_init(&merged, mt);
237238

238239
for (size_t i = 0; i < mt->stack_len; i++) {
239-
reftable_record_init(&merged.subiters[merged.stack_len].rec,
240+
reftable_record_init(&merged.subiters[i].rec,
240241
reftable_record_type(rec));
241242

242243
err = reftable_table_seek_record(&mt->stack[i],
243-
&merged.subiters[merged.stack_len].iter, rec);
244+
&merged.subiters[i].iter, rec);
244245
if (err < 0)
245246
goto out;
246247
if (err > 0)
247248
continue;
248249

249-
err = merged_iter_advance_subiter(&merged, merged.stack_len);
250+
err = merged_iter_advance_subiter(&merged, i);
250251
if (err < 0)
251252
goto out;
252-
253-
merged.stack_len++;
254253
}
255254

256255
p = reftable_malloc(sizeof(*p));

0 commit comments

Comments
 (0)