Skip to content

Commit f1e3c12

Browse files
pks-tgitster
authored andcommitted
reftable/reader: inline reader_seek_internal()
We have both `reader_seek()` and `reader_seek_internal()`, where the former function only exists so that we can exit early in case the given table has no records of the sought-after type. Merge these two functions into one. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 81a03a3 commit f1e3c12

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

reftable/reader.c

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -573,21 +573,25 @@ static int table_iter_seek_indexed(struct table_iter *ti,
573573
return err;
574574
}
575575

576-
static int reader_seek_internal(struct reftable_reader *r,
577-
struct reftable_iterator *it,
578-
struct reftable_record *rec)
576+
static int reader_seek(struct reftable_reader *r, struct reftable_iterator *it,
577+
struct reftable_record *rec)
579578
{
580-
struct reftable_reader_offsets *offs =
581-
reader_offsets_for(r, reftable_record_type(rec));
582-
uint64_t idx = offs->index_offset;
579+
uint8_t typ = reftable_record_type(rec);
580+
struct reftable_reader_offsets *offs = reader_offsets_for(r, typ);
583581
struct table_iter ti = TABLE_ITER_INIT, *p;
584582
int err;
585583

586-
err = table_iter_seek_start(&ti, r, reftable_record_type(rec), !!idx);
584+
if (!offs->is_present) {
585+
iterator_set_empty(it);
586+
return 0;
587+
}
588+
589+
err = table_iter_seek_start(&ti, r, reftable_record_type(rec),
590+
!!offs->index_offset);
587591
if (err < 0)
588592
goto out;
589593

590-
if (idx)
594+
if (offs->index_offset)
591595
err = table_iter_seek_indexed(&ti, rec);
592596
else
593597
err = table_iter_seek_linear(&ti, rec);
@@ -604,20 +608,6 @@ static int reader_seek_internal(struct reftable_reader *r,
604608
return err;
605609
}
606610

607-
static int reader_seek(struct reftable_reader *r, struct reftable_iterator *it,
608-
struct reftable_record *rec)
609-
{
610-
uint8_t typ = reftable_record_type(rec);
611-
612-
struct reftable_reader_offsets *offs = reader_offsets_for(r, typ);
613-
if (!offs->is_present) {
614-
iterator_set_empty(it);
615-
return 0;
616-
}
617-
618-
return reader_seek_internal(r, it, rec);
619-
}
620-
621611
int reftable_reader_seek_ref(struct reftable_reader *r,
622612
struct reftable_iterator *it, const char *name)
623613
{

0 commit comments

Comments
 (0)