aboutsummaryrefslogtreecommitdiffstats
path: root/reftable/table.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-04-07 15:16:23 +0200
committerJunio C Hamano <gitster@pobox.com>2025-04-07 14:53:11 -0700
commit6da48a5e00ae77c4092e78ac8ac8641a90660343 (patch)
tree5e0241841f4538cafe58f86d1994d2c1ba7ec62d /reftable/table.c
parent156d79cef0de565408e41f840bbda87114367977 (diff)
downloadgit-6da48a5e00ae77c4092e78ac8ac8641a90660343.tar.gz
reftable/block: make block iterators reseekable
Refactor the block iterators so that initialization and seeking are different from one another. This makes the iterator trivially reseekable by storing the pointer to the block at initialization time, which we can then reuse on every seek. This refactoring prepares the code for exposing a `reftable_iterator` interface for blocks in a subsequent commit. Callsites are adjusted accordingly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'reftable/table.c')
-rw-r--r--reftable/table.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/reftable/table.c b/reftable/table.c
index ef1f33c92f..50ffad7edc 100644
--- a/reftable/table.c
+++ b/reftable/table.c
@@ -208,7 +208,7 @@ static int table_iter_next_block(struct table_iter *ti)
ti->block_off = next_block_off;
ti->is_finished = 0;
- block_iter_seek_start(&ti->bi, &ti->block);
+ block_iter_init(&ti->bi, &ti->block);
return 0;
}
@@ -256,7 +256,7 @@ static int table_iter_seek_to(struct table_iter *ti, uint64_t off, uint8_t typ)
ti->typ = reftable_block_type(&ti->block);
ti->block_off = off;
- block_iter_seek_start(&ti->bi, &ti->block);
+ block_iter_init(&ti->bi, &ti->block);
ti->is_finished = 0;
return 0;
}
@@ -349,7 +349,8 @@ static int table_iter_seek_linear(struct table_iter *ti,
* the wanted key inside of it. If the block does not contain our key
* we know that the corresponding record does not exist.
*/
- err = block_iter_seek_key(&ti->bi, &ti->block, &want_key);
+ block_iter_init(&ti->bi, &ti->block);
+ err = block_iter_seek_key(&ti->bi, &want_key);
if (err < 0)
goto done;
err = 0;
@@ -417,7 +418,9 @@ static int table_iter_seek_indexed(struct table_iter *ti,
if (err != 0)
goto done;
- err = block_iter_seek_key(&ti->bi, &ti->block, &want_index.u.idx.last_key);
+ block_iter_init(&ti->bi, &ti->block);
+
+ err = block_iter_seek_key(&ti->bi, &want_index.u.idx.last_key);
if (err < 0)
goto done;