Skip to content

Commit

Permalink
Use ZIP file size metadata to allocate string
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Aug 21, 2024
1 parent 0c98b59 commit 2d42a4b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/ruff_db/src/vendored.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ impl VendoredFileSystem {
fn read_to_string(fs: &VendoredFileSystem, path: &VendoredPath) -> Result<String> {
let mut archive = fs.lock_archive();
let mut zip_file = archive.lookup_path(&NormalizedVendoredPath::from(path))?;
let mut buffer = String::new();

let mut buffer = String::with_capacity(
usize::try_from(zip_file.size())
.unwrap_or(usize::MAX)
.min(10_000_000),
);
zip_file.read_to_string(&mut buffer)?;
Ok(buffer)
}
Expand Down

0 comments on commit 2d42a4b

Please sign in to comment.