about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2021-10-05 12:52:49 -0700
committerGitHub <noreply@github.com>2021-10-05 12:52:49 -0700
commit5f8b1614d110fc3f0cd8536e08822a8cead32172 (patch)
tree411ef5015faad89dc56928c2040b47fd2cff070f /compiler
parentf71b3e2b46505fda8dea7187fa90b80472f7abfa (diff)
parentc35a700be2aebc0449a16fa1a09d7667aa209230 (diff)
downloadrust-5f8b1614d110fc3f0cd8536e08822a8cead32172.tar.gz
rust-5f8b1614d110fc3f0cd8536e08822a8cead32172.zip
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.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_metadata/src/locator.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs
index abdac78ae24..9b1ea3b4c4c 100644
--- a/compiler/rustc_metadata/src/locator.rs
+++ b/compiler/rustc_metadata/src/locator.rs
@@ -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(_) => {