Mercurial > lbo > hg > sstable
changeset 103:8c56c0acf795
Avoid doing 3 io requests when reading a block
author | Anton Romanov <theli.ua@gmail.com> |
---|---|
date | Sat, 25 Apr 2020 12:44:51 -0700 |
parents | 41d531d9ee5a |
children | 03950ebabe06 |
files | src/table_block.rs |
diffstat | 1 files changed, 10 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/table_block.rs Sat Apr 25 09:40:51 2020 +0200 +++ b/src/table_block.rs Sat Apr 25 12:44:51 2020 -0700 @@ -44,21 +44,16 @@ // The block is denoted by offset and length in BlockHandle. A block in an encoded // table is followed by 1B compression type and 4B checksum. // The checksum refers to the compressed contents. - let buf = read_bytes(f, location)?; - let compress = read_bytes( - f, - &BlockHandle::new( - location.offset() + location.size(), - table_builder::TABLE_BLOCK_COMPRESS_LEN, - ), - )?; - let cksum = read_bytes( - f, - &BlockHandle::new( - location.offset() + location.size() + table_builder::TABLE_BLOCK_COMPRESS_LEN, - table_builder::TABLE_BLOCK_CKSUM_LEN, - ), - )?; + + let block_data_size = location.size(); + let location = BlockHandle::new( + location.offset(), + block_data_size + table_builder::TABLE_BLOCK_CKSUM_LEN + table_builder::TABLE_BLOCK_COMPRESS_LEN, + ); + let mut buf = read_bytes(f, &location)?; + + let mut compress = buf.split_off(block_data_size); + let cksum = compress.split_off(table_builder::TABLE_BLOCK_COMPRESS_LEN); if !verify_table_block(&buf, compress[0], unmask_crc(u32::decode_fixed(&cksum))) { return err(