Skip to content

Commit

Permalink
Make an initial guess for metadata size to reduce buffer resizes
Browse files Browse the repository at this point in the history
  • Loading branch information
joshtriplett committed Oct 5, 2021
1 parent 2b6ed3b commit c35a700
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/rustc_metadata/src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {
Expand Down

0 comments on commit c35a700

Please sign in to comment.