git/reftable/merged.h
Patrick Steinhardt 829231dc20 reftable/merged: reuse buffer to compute record keys
When iterating over entries in the merged iterator's queue, we compute
the key of each of the entries and write it into a buffer. We do not
reuse the buffer though and thus re-allocate it on every iteration,
which is wasteful given that we never transfer ownership of the
allocated bytes outside of the loop.

Refactor the code to reuse the buffer. This also fixes a potential
memory leak when `merged_iter_advance_subiter()` returns an error.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-12-11 07:23:16 -08:00

41 lines
808 B
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 MERGED_H
#define MERGED_H
#include "pq.h"
struct reftable_merged_table {
struct reftable_table *stack;
size_t stack_len;
uint32_t hash_id;
/* If unset, produce deletions. This is useful for compaction. For the
* full stack, deletions should be produced. */
int suppress_deletions;
uint64_t min;
uint64_t max;
};
struct merged_iter {
struct reftable_iterator *stack;
uint32_t hash_id;
size_t stack_len;
uint8_t typ;
int suppress_deletions;
struct merged_iter_pqueue pq;
struct strbuf key;
struct strbuf entry_key;
};
void merged_table_release(struct reftable_merged_table *mt);
#endif