Skip to content

Commit 8aaeffe

Browse files
pks-tgitster
authored andcommitted
reftable/writer: reset last_key instead of releasing it
The reftable writer tracks the last key that it has written so that it can properly compute the compressed prefix for the next record it is about to write. This last key must be reset whenever we move on to write the next block, which is done in `writer_reinit_block_writer()`. We do this by calling `strbuf_release()` though, which needlessly deallocates the underlying buffer. Convert the code to use `strbuf_reset()` instead, which saves one allocation per block we're about to write. This requires us to also amend `reftable_writer_free()` to release the buffer's memory now as we previously seemingly relied on `writer_reinit_block_writer()` to release the memory for us. Releasing memory here is the right thing to do anyway. While at it, convert a callsite where we truncate the buffer by setting its length to zero to instead use `strbuf_reset()`, too. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 60dd319 commit 8aaeffe

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

reftable/writer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static void writer_reinit_block_writer(struct reftable_writer *w, uint8_t typ)
109109
block_start = header_size(writer_version(w));
110110
}
111111

112-
strbuf_release(&w->last_key);
112+
strbuf_reset(&w->last_key);
113113
block_writer_init(&w->block_writer_data, typ, w->block,
114114
w->opts.block_size, block_start,
115115
hash_size(w->opts.hash_id));
@@ -478,7 +478,7 @@ static int writer_finish_section(struct reftable_writer *w)
478478
bstats->max_index_level = max_level;
479479

480480
/* Reinit lastKey, as the next section can start with any key. */
481-
w->last_key.len = 0;
481+
strbuf_reset(&w->last_key);
482482

483483
return 0;
484484
}

0 commit comments

Comments
 (0)