From 625e0797dbb28f7e145f7ada6036b9ee8fc2f273 Mon Sep 17 00:00:00 2001 From: Matthew Kim <38759997+friendlymatthew@users.noreply.github.com> Date: Thu, 2 Jan 2025 21:01:56 -0500 Subject: [PATCH] Gate properly --- src/crc32.rs | 5 +++-- src/decoder.rs | 11 ++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/crc32.rs b/src/crc32.rs index 9050332..8bca2c3 100644 --- a/src/crc32.rs +++ b/src/crc32.rs @@ -1,5 +1,5 @@ #[cfg(all(target_arch = "aarch64", target_feature = "crc"))] -pub fn compute_crc_aarch64<'a>(chunk_type: &'a [u8], chunk_data: &'a [u8]) -> u32 { +pub fn compute_crc<'a>(chunk_type: &'a [u8], chunk_data: &'a [u8]) -> u32 { use std::arch::aarch64::__crc32b; let mut crc = 0xffff_ffff; @@ -15,7 +15,8 @@ pub fn compute_crc_aarch64<'a>(chunk_type: &'a [u8], chunk_data: &'a [u8]) -> u3 !crc } -pub fn compute_crc_fast<'a>(chunk_type: &'a [u8], chunk_data: &'a [u8]) -> u32 { +#[cfg(not(all(target_arch = "aarch64", target_feature = "crc")))] +pub fn compute_crc<'a>(chunk_type: &'a [u8], chunk_data: &'a [u8]) -> u32 { use crc32fast::Hasher; let mut hx = Hasher::new(); diff --git a/src/decoder.rs b/src/decoder.rs index 40c64cf..bcf6a80 100644 --- a/src/decoder.rs +++ b/src/decoder.rs @@ -3,10 +3,7 @@ use std::{collections::BTreeMap, io::Read}; use anyhow::{bail, ensure, Result}; use flate2::read::ZlibDecoder; -#[cfg(all(target_arch = "aarch64", target_feature = "crc"))] -use crate::crc32::compute_crc_aarch64; - -use crate::{crc32::compute_crc_fast, Chunk, ColorType, Filter, ImageHeader, Png}; +use crate::{crc32::compute_crc, Chunk, ColorType, Filter, ImageHeader, Png}; #[derive(Debug)] pub struct Decoder<'a> { @@ -195,11 +192,7 @@ impl<'a> Decoder<'a> { } fn validate_crc(&self, chunk_type: &'a [u8], chunk_data: &'a [u8], expected_crc: u32) -> bool { - let computed_crc = if cfg!(all(target_arch = "aarch64", target_feature = "crc")) { - compute_crc_aarch64(chunk_type, chunk_data) - } else { - compute_crc_fast(chunk_type, chunk_data) - }; + let computed_crc = compute_crc(chunk_type, chunk_data); computed_crc == expected_crc }