Skip to content

Commit 90eedab

Browse files
committed
Merge branch 'ps/reftable-read-block-perffix'
Performance regression in not-yet-released code has been corrected. * ps/reftable-read-block-perffix: reftable: fix perf regression when reading blocks of unwanted type
2 parents 2b33031 + 1970333 commit 90eedab

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

reftable/block.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ static int read_block(struct reftable_block_source *source,
227227
int reftable_block_init(struct reftable_block *block,
228228
struct reftable_block_source *source,
229229
uint32_t offset, uint32_t header_size,
230-
uint32_t table_block_size, uint32_t hash_size)
230+
uint32_t table_block_size, uint32_t hash_size,
231+
uint8_t want_type)
231232
{
232233
uint32_t guess_block_size = table_block_size ?
233234
table_block_size : DEFAULT_BLOCK_SIZE;
@@ -247,6 +248,10 @@ int reftable_block_init(struct reftable_block *block,
247248
err = REFTABLE_FORMAT_ERROR;
248249
goto done;
249250
}
251+
if (want_type != REFTABLE_BLOCK_TYPE_ANY && block_type != want_type) {
252+
err = 1;
253+
goto done;
254+
}
250255

251256
block_size = reftable_get_be24(block->block_data.data + header_size + 1);
252257
if (block_size > guess_block_size) {

reftable/reftable-block.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ struct reftable_block {
5656
int reftable_block_init(struct reftable_block *b,
5757
struct reftable_block_source *source,
5858
uint32_t offset, uint32_t header_size,
59-
uint32_t table_block_size, uint32_t hash_size);
59+
uint32_t table_block_size, uint32_t hash_size,
60+
uint8_t want_type);
6061

6162
/* Release resources allocated by the block. */
6263
void reftable_block_release(struct reftable_block *b);

reftable/table.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,7 @@ int table_init_block(struct reftable_table *t, struct reftable_block *block,
173173
return 1;
174174

175175
err = reftable_block_init(block, &t->source, next_off, header_off,
176-
t->block_size, hash_size(t->hash_id));
177-
if (err < 0)
178-
goto done;
179-
180-
if (want_typ != REFTABLE_BLOCK_TYPE_ANY && block->block_type != want_typ) {
181-
err = 1;
182-
goto done;
183-
}
184-
185-
done:
176+
t->block_size, hash_size(t->hash_id), want_typ);
186177
if (err)
187178
reftable_block_release(block);
188179
return err;

t/unit-tests/t-reftable-block.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ static void t_ref_block_read_write(void)
6464
block_writer_release(&bw);
6565

6666
block_source_from_buf(&source ,&block_data);
67-
reftable_block_init(&block, &source, 0, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
67+
reftable_block_init(&block, &source, 0, header_off, block_size,
68+
REFTABLE_HASH_SIZE_SHA1, REFTABLE_BLOCK_TYPE_REF);
6869

6970
block_iter_init(&it, &block);
7071

@@ -153,7 +154,8 @@ static void t_log_block_read_write(void)
153154
block_writer_release(&bw);
154155

155156
block_source_from_buf(&source, &block_data);
156-
reftable_block_init(&block, &source, 0, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
157+
reftable_block_init(&block, &source, 0, header_off, block_size,
158+
REFTABLE_HASH_SIZE_SHA1, REFTABLE_BLOCK_TYPE_LOG);
157159

158160
block_iter_init(&it, &block);
159161

@@ -245,7 +247,8 @@ static void t_obj_block_read_write(void)
245247
block_writer_release(&bw);
246248

247249
block_source_from_buf(&source, &block_data);
248-
reftable_block_init(&block, &source, 0, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
250+
reftable_block_init(&block, &source, 0, header_off, block_size,
251+
REFTABLE_HASH_SIZE_SHA1, REFTABLE_BLOCK_TYPE_OBJ);
249252

250253
block_iter_init(&it, &block);
251254

@@ -329,7 +332,8 @@ static void t_index_block_read_write(void)
329332
block_writer_release(&bw);
330333

331334
block_source_from_buf(&source, &block_data);
332-
reftable_block_init(&block, &source, 0, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
335+
reftable_block_init(&block, &source, 0, header_off, block_size,
336+
REFTABLE_HASH_SIZE_SHA1, REFTABLE_BLOCK_TYPE_INDEX);
333337

334338
block_iter_init(&it, &block);
335339

@@ -411,7 +415,8 @@ static void t_block_iterator(void)
411415
check_int(err, >, 0);
412416

413417
block_source_from_buf(&source, &data);
414-
reftable_block_init(&block, &source, 0, 0, data.len, REFTABLE_HASH_SIZE_SHA1);
418+
reftable_block_init(&block, &source, 0, 0, data.len,
419+
REFTABLE_HASH_SIZE_SHA1, REFTABLE_BLOCK_TYPE_REF);
415420

416421
err = reftable_block_init_iterator(&block, &it);
417422
check_int(err, ==, 0);

0 commit comments

Comments
 (0)