Skip to content

Commit 080f8c4

Browse files
pks-tgitster
authored andcommitted
reftable/merged: avoid duplicate pqueue emptiness check
When calling `merged_iter_next_void()` we first check whether the iter has been exhausted already. We already perform this check two levels down the stack in `merged_iter_next_entry()` though, which makes this check redundant. Now if this check was there to accelerate the common case it might have made sense to keep it. But the iterator being exhausted is rather the uncommon case because you can expect most reftable stacks to contain more than two refs. Simplify the code by removing the check. As `merged_iter_next_void()` is basically empty except for calling `merged_iter_next()` now, merge these two functions. This also results in a tiny speedup when iterating over many refs: Benchmark 1: show-ref: single matching ref (revision = HEAD~) Time (mean ± σ): 125.6 ms ± 3.8 ms [User: 122.7 ms, System: 2.8 ms] Range (min … max): 122.4 ms … 153.4 ms 1000 runs Benchmark 2: show-ref: single matching ref (revision = HEAD) Time (mean ± σ): 124.0 ms ± 3.9 ms [User: 121.1 ms, System: 2.8 ms] Range (min … max): 120.1 ms … 156.4 ms 1000 runs Summary show-ref: single matching ref (revision = HEAD) ran 1.01 ± 0.04 times faster than show-ref: single matching ref (revision = HEAD~) Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f8c1a8e commit 080f8c4

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

reftable/merged.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,27 +148,19 @@ static int merged_iter_next_entry(struct merged_iter *mi,
148148
return 0;
149149
}
150150

151-
static int merged_iter_next(struct merged_iter *mi, struct reftable_record *rec)
151+
static int merged_iter_next_void(void *p, struct reftable_record *rec)
152152
{
153+
struct merged_iter *mi = p;
153154
while (1) {
154155
int err = merged_iter_next_entry(mi, rec);
155-
if (err == 0 && mi->suppress_deletions &&
156-
reftable_record_is_deletion(rec)) {
156+
if (err)
157+
return err;
158+
if (mi->suppress_deletions && reftable_record_is_deletion(rec))
157159
continue;
158-
}
159-
160-
return err;
160+
return 0;
161161
}
162162
}
163163

164-
static int merged_iter_next_void(void *p, struct reftable_record *rec)
165-
{
166-
struct merged_iter *mi = p;
167-
if (merged_iter_pqueue_is_empty(mi->pq) && mi->advance_index < 0)
168-
return 1;
169-
return merged_iter_next(mi, rec);
170-
}
171-
172164
static struct reftable_iterator_vtable merged_iter_vtable = {
173165
.next = &merged_iter_next_void,
174166
.close = &merged_iter_close,

0 commit comments

Comments
 (0)