Skip to content

Commit c35a700

Browse files
committed
Make an initial guess for metadata size to reduce buffer resizes
1 parent 2b6ed3b commit c35a700

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

compiler/rustc_metadata/src/locator.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,9 @@ fn get_metadata_section(
740740
// Header is okay -> inflate the actual metadata
741741
let compressed_bytes = &buf[header_len..];
742742
debug!("inflating {} bytes of compressed metadata", compressed_bytes.len());
743-
let mut inflated = Vec::new();
743+
// Assume the decompressed data will be at least the size of the compressed data, so we
744+
// don't have to grow the buffer as much.
745+
let mut inflated = Vec::with_capacity(compressed_bytes.len());
744746
match FrameDecoder::new(compressed_bytes).read_to_end(&mut inflated) {
745747
Ok(_) => rustc_erase_owner!(OwningRef::new(inflated).map_owner_box()),
746748
Err(_) => {

0 commit comments

Comments
 (0)