mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Rollup merge of #89546 - joshtriplett:grow-metadata-faster, r=petrochenkov
Make an initial guess for metadata size to reduce buffer resizes When reading metadata, the compiler starts with a `Vec::new()`, which will need to grow repeatedly as the metadata gets decompressed into it. Reduce the number of resizes by starting out at the size of the compressed data.
This commit is contained in:
commit
5f8b1614d1
@ -740,7 +740,9 @@ fn get_metadata_section(
|
||||
// Header is okay -> inflate the actual metadata
|
||||
let compressed_bytes = &buf[header_len..];
|
||||
debug!("inflating {} bytes of compressed metadata", compressed_bytes.len());
|
||||
let mut inflated = Vec::new();
|
||||
// Assume the decompressed data will be at least the size of the compressed data, so we
|
||||
// don't have to grow the buffer as much.
|
||||
let mut inflated = Vec::with_capacity(compressed_bytes.len());
|
||||
match FrameDecoder::new(compressed_bytes).read_to_end(&mut inflated) {
|
||||
Ok(_) => rustc_erase_owner!(OwningRef::new(inflated).map_owner_box()),
|
||||
Err(_) => {
|
||||
|
Loading…
Reference in New Issue
Block a user