git/reftable/iter.h
Patrick Steinhardt 2d71a1d4a2 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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-03-04 10:19:39 -08:00

65 lines
1.5 KiB
C

/*
Copyright 2020 Google LLC
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file or at
https://developers.google.com/open-source/licenses/bsd
*/
#ifndef ITER_H
#define ITER_H
#include "system.h"
#include "block.h"
#include "record.h"
#include "reftable-iterator.h"
#include "reftable-generic.h"
/* iterator that produces only ref records that point to `oid` */
struct filtering_ref_iterator {
int double_check;
struct reftable_table tab;
struct strbuf oid;
struct reftable_iterator it;
};
#define FILTERING_REF_ITERATOR_INIT \
{ \
.oid = STRBUF_INIT \
}
void iterator_from_filtering_ref_iterator(struct reftable_iterator *,
struct filtering_ref_iterator *);
/* iterator that produces only ref records that point to `oid`,
* but using the object index.
*/
struct indexed_table_ref_iter {
struct reftable_reader *r;
struct strbuf oid;
/* mutable */
uint64_t *offsets;
/* Points to the next offset to read. */
int offset_idx;
int offset_len;
struct block_reader block_reader;
struct block_iter cur;
int is_finished;
};
#define INDEXED_TABLE_REF_ITER_INIT { \
.cur = BLOCK_ITER_INIT, \
.oid = STRBUF_INIT, \
}
void iterator_from_indexed_table_ref_iter(struct reftable_iterator *it,
struct indexed_table_ref_iter *itr);
/* Takes ownership of `offsets` */
int new_indexed_table_ref_iter(struct indexed_table_ref_iter **dest,
struct reftable_reader *r, uint8_t *oid,
int oid_len, uint64_t *offsets, int offset_len);
#endif