Preallocate vector on reading in file
Provides 1.5% overall speedup on -o4
This commit is contained in:
parent
eb739c9ff9
commit
cf5b90b444
2 changed files with 3 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
### Version 0.19.1 (unreleased)
|
||||
- Refactor of internal code.
|
||||
- Implement unix-specific permissions copying for `-p` option
|
||||
- Performance optimizations
|
||||
|
||||
### Version 0.19.0
|
||||
- [SEMVER_MAJOR] Default to overwriting the input file if `out_file` is not set.
|
||||
|
|
|
|||
|
|
@ -73,7 +73,8 @@ impl PngData {
|
|||
return Err(PngError::new("Failed to read from file"));
|
||||
}
|
||||
// Read raw png data into memory
|
||||
let mut byte_data: Vec<u8> = Vec::new();
|
||||
let mut byte_data: Vec<u8> =
|
||||
Vec::with_capacity(file.metadata().map(|m| m.len() as usize).unwrap_or(0));
|
||||
match file.read_to_end(&mut byte_data) {
|
||||
Ok(_) => (),
|
||||
Err(_) => return Err(PngError::new("Failed to read from file")),
|
||||
|
|
|
|||
Loading…
Reference in a new issue