From d2cebc3c2d8796544a9b023270504ed576fd034f Mon Sep 17 00:00:00 2001 From: Kornel Date: Tue, 15 Jun 2021 14:07:32 +0100 Subject: [PATCH] Don't allocate reduced buffer until needed --- src/reduction/bit_depth.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reduction/bit_depth.rs b/src/reduction/bit_depth.rs index 75ad95df..aef295cf 100644 --- a/src/reduction/bit_depth.rs +++ b/src/reduction/bit_depth.rs @@ -75,7 +75,6 @@ pub fn reduce_bit_depth(png: &PngImage, minimum_bits: usize) -> Option #[must_use] pub fn reduce_bit_depth_8_or_less(png: &PngImage, mut minimum_bits: usize) -> Option { assert!((1..8).contains(&minimum_bits)); - let mut reduced = BitVec::with_capacity(png.data.len() * 8); let bit_depth: usize = png.ihdr.bit_depth.as_u8() as usize; if minimum_bits >= bit_depth { return None; @@ -130,6 +129,7 @@ pub fn reduce_bit_depth_8_or_less(png: &PngImage, mut minimum_bits: usize) -> Op } } + let mut reduced = BitVec::with_capacity(png.data.len() * 8); for line in png.scan_lines() { reduced.extend(BitVec::from_bytes(&[line.filter])); let bit_vec = BitVec::from_bytes(&line.data);