Preallocate memory in reduced_alpha_to_up (#180)

This commit is contained in:
Kamal Ahmad 2019-06-27 22:44:49 +05:00 committed by Josh Holmer
parent 56b94542a6
commit 34ee78dbbc

View file

@ -93,11 +93,11 @@ fn reduced_alpha_to_white(png: &PngImage, bpc: usize, bpp: usize) -> Vec<u8> {
}
fn reduced_alpha_to_up(png: &PngImage, bpc: usize, bpp: usize) -> Vec<u8> {
let mut lines = Vec::new();
let mut scan_lines = png.scan_lines().collect::<Vec<ScanLine<'_>>>();
scan_lines.reverse();
let mut lines = Vec::with_capacity(scan_lines.len());
let mut last_line = Vec::new();
let mut current_line = Vec::with_capacity(last_line.len());
let mut current_line = Vec::with_capacity(scan_lines[0].data.len() + 1); // filter size + pixels
for line in scan_lines {
if line.data.len() != last_line.len() {
last_line = vec![0; line.data.len()];