Git fork

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

+19 -17
+6 -1
reftable/block.c
··· 227 227 int reftable_block_init(struct reftable_block *block, 228 228 struct reftable_block_source *source, 229 229 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) 231 232 { 232 233 uint32_t guess_block_size = table_block_size ? 233 234 table_block_size : DEFAULT_BLOCK_SIZE; ··· 245 246 block_type = block->block_data.data[header_size]; 246 247 if (!reftable_is_block_type(block_type)) { 247 248 err = REFTABLE_FORMAT_ERROR; 249 + goto done; 250 + } 251 + if (want_type != REFTABLE_BLOCK_TYPE_ANY && block_type != want_type) { 252 + err = 1; 248 253 goto done; 249 254 } 250 255
+2 -1
reftable/reftable-block.h
··· 56 56 int reftable_block_init(struct reftable_block *b, 57 57 struct reftable_block_source *source, 58 58 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); 60 61 61 62 /* Release resources allocated by the block. */ 62 63 void reftable_block_release(struct reftable_block *b);
+1 -10
reftable/table.c
··· 173 173 return 1; 174 174 175 175 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); 186 177 if (err) 187 178 reftable_block_release(block); 188 179 return err;
+10 -5
t/unit-tests/t-reftable-block.c
··· 64 64 block_writer_release(&bw); 65 65 66 66 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); 68 69 69 70 block_iter_init(&it, &block); 70 71 ··· 153 154 block_writer_release(&bw); 154 155 155 156 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); 157 159 158 160 block_iter_init(&it, &block); 159 161 ··· 245 247 block_writer_release(&bw); 246 248 247 249 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); 249 252 250 253 block_iter_init(&it, &block); 251 254 ··· 329 332 block_writer_release(&bw); 330 333 331 334 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); 333 337 334 338 block_iter_init(&it, &block); 335 339 ··· 411 415 check_int(err, >, 0); 412 416 413 417 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); 415 420 416 421 err = reftable_block_init_iterator(&block, &it); 417 422 check_int(err, ==, 0);