From d2cebc3c2d8796544a9b023270504ed576fd034f Mon Sep 17 00:00:00 2001 From: Kornel Date: Tue, 15 Jun 2021 14:07:32 +0100 Subject: [PATCH 1/3] 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); From f8bb4fa63715349aa893407df4b57de10cafa1fe Mon Sep 17 00:00:00 2001 From: Kornel Date: Tue, 15 Jun 2021 12:33:03 +0100 Subject: [PATCH 2/3] Fix tests without default features --- tests/flags.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/flags.rs b/tests/flags.rs index 69d79f6a..6da0ac62 100644 --- a/tests/flags.rs +++ b/tests/flags.rs @@ -494,6 +494,7 @@ fn fix_errors() { } #[test] +#[cfg(feature = "zopfli")] fn zopfli_mode() { let input = PathBuf::from("tests/files/zopfli_mode.png"); let (output, mut opts) = get_opts(&input); @@ -511,6 +512,7 @@ fn zopfli_mode() { } #[test] +#[cfg(feature = "libdeflater")] fn libdeflater_mode() { let input = PathBuf::from("tests/files/zopfli_mode.png"); let (output, mut opts) = get_opts(&input); From dac408627b97f05c7b6e5224fb9979ca78784c03 Mon Sep 17 00:00:00 2001 From: Kornel Date: Tue, 15 Jun 2021 14:10:38 +0100 Subject: [PATCH 3/3] bit-vec is too slow for debug mode --- Cargo.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 57111fae..5a5f19a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -78,7 +78,12 @@ parallel = ["rayon", "indexmap/rayon"] [lib] name = "oxipng" path = "src/lib.rs" + [profile.dev] opt-level = 2 + [profile.release] lto = "thin" + +[profile.dev.package.bit-vec] +opt-level = 3