]> git.ipfire.org Git - thirdparty/git.git/commit
reftable/reader: add comments to `table_iter_next()`
authorPatrick Steinhardt <ps@pks.im>
Mon, 12 Feb 2024 08:32:57 +0000 (09:32 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 12 Feb 2024 17:19:27 +0000 (09:19 -0800)
commitc68ca7abd30b22404ce59d5133566729c07ffe8f
tree811abd5e736164b7280f3de270c781f6eef6bcd3
parenta418a7abef72132eff23e783f80f8c88b3c63266
reftable/reader: add comments to `table_iter_next()`

While working on the optimizations in the preceding patches I stumbled
upon `table_iter_next()` multiple times. It is quite easy to miss the
fact that we don't call `table_iter_next_in_block()` twice, but that the
second call is in fact `table_iter_next_block()`.

Add comments to explain what exactly is going on here to make things
more obvious. While at it, touch up the code to conform to our code
style better.

Note that one of the refactorings merges two conditional blocks into
one. Before, we had the following code:

```
err = table_iter_next_block(&next, ti);
if (err != 0) {
ti->is_finished = 1;
}
table_iter_block_done(ti);
if (err != 0) {
return err;
}
```

As `table_iter_block_done()` does not care about `is_finished`, the
conditional blocks can be merged into one block:

```
err = table_iter_next_block(&next, ti);
table_iter_block_done(ti);
if (err != 0) {
ti->is_finished = 1;
return err;
}
```

This is both easier to reason about and more performant because we have
one branch less.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
reftable/reader.c