Skip to content

Commit 2d71a1d

Browse files
pks-tgitster
authored andcommitted
reftable/merged: remove unnecessary null check for subiters
Whenever we advance a subiter we first call `iterator_is_null()`. This is not needed though because we only ever advance subiters which have entries in the priority queue, and we do not end entries to the priority queue when the subiter has been exhausted. Drop the check as well as the now-unused function. This results in a surprisingly big speedup: Benchmark 1: show-ref: single matching ref (revision = HEAD~) Time (mean ± σ): 138.1 ms ± 4.4 ms [User: 135.1 ms, System: 2.8 ms] Range (min … max): 133.4 ms … 167.3 ms 1000 runs Benchmark 2: show-ref: single matching ref (revision = HEAD) Time (mean ± σ): 134.4 ms ± 4.2 ms [User: 131.5 ms, System: 2.8 ms] Range (min … max): 130.0 ms … 164.0 ms 1000 runs Summary show-ref: single matching ref (revision = HEAD) ran 1.03 ± 0.05 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 bb2d6be commit 2d71a1d

File tree

3 files changed

+1
-18
lines changed

3 files changed

+1
-18
lines changed

reftable/iter.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ license that can be found in the LICENSE file or at
1616
#include "reader.h"
1717
#include "reftable-error.h"
1818

19-
int iterator_is_null(struct reftable_iterator *it)
20-
{
21-
return !it->ops;
22-
}
23-
2419
static void filtering_ref_iterator_close(void *iter_arg)
2520
{
2621
struct filtering_ref_iterator *fri = iter_arg;

reftable/iter.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ license that can be found in the LICENSE file or at
1616
#include "reftable-iterator.h"
1717
#include "reftable-generic.h"
1818

19-
/* Returns true for a zeroed out iterator, such as the one returned from
20-
* iterator_destroy. */
21-
int iterator_is_null(struct reftable_iterator *it);
22-
2319
/* iterator that produces only ref records that point to `oid` */
2420
struct filtering_ref_iterator {
2521
int double_check;

reftable/merged.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ static void merged_iter_close(void *p)
7070
reftable_free(mi->subiters);
7171
}
7272

73-
static int merged_iter_advance_nonnull_subiter(struct merged_iter *mi,
74-
size_t idx)
73+
static int merged_iter_advance_subiter(struct merged_iter *mi, size_t idx)
7574
{
7675
struct pq_entry e = {
7776
.index = idx,
@@ -92,13 +91,6 @@ static int merged_iter_advance_nonnull_subiter(struct merged_iter *mi,
9291
return 0;
9392
}
9493

95-
static int merged_iter_advance_subiter(struct merged_iter *mi, size_t idx)
96-
{
97-
if (iterator_is_null(&mi->subiters[idx].iter))
98-
return 0;
99-
return merged_iter_advance_nonnull_subiter(mi, idx);
100-
}
101-
10294
static int merged_iter_next_entry(struct merged_iter *mi,
10395
struct reftable_record *rec)
10496
{

0 commit comments

Comments
 (0)