From 34ee78dbbc4f0ccaf2b10c4ede210ddae97e5fff Mon Sep 17 00:00:00 2001 From: Kamal Ahmad Date: Thu, 27 Jun 2019 22:44:49 +0500 Subject: [PATCH] Preallocate memory in reduced_alpha_to_up (#180) --- src/reduction/alpha.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/reduction/alpha.rs b/src/reduction/alpha.rs index 089f7cc3..b255e9f7 100644 --- a/src/reduction/alpha.rs +++ b/src/reduction/alpha.rs @@ -93,11 +93,11 @@ fn reduced_alpha_to_white(png: &PngImage, bpc: usize, bpp: usize) -> Vec { } fn reduced_alpha_to_up(png: &PngImage, bpc: usize, bpp: usize) -> Vec { - let mut lines = Vec::new(); let mut scan_lines = png.scan_lines().collect::>>(); 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()];