diff --git a/Cargo.toml b/Cargo.toml index 0680df05..f639222a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,8 @@ build_stub_miniz = [] no_c_export = [] libc_stub = [] +simd = ['miniz_oxide/simd'] + [profile.dev] panic = "abort" diff --git a/miniz_oxide/Cargo.toml b/miniz_oxide/Cargo.toml index a2084dd0..7993ddbe 100644 --- a/miniz_oxide/Cargo.toml +++ b/miniz_oxide/Cargo.toml @@ -22,6 +22,7 @@ autocfg = "1.0" [dependencies] adler = { version = "1.0", default-features = false } +simd-adler32 = { version = "0.3", default-features = false, optional = true } # Internal feature, only used when building as part of libstd, not part of the # stable interface of this crate. @@ -30,8 +31,12 @@ alloc = { version = '1.0.0', optional = true, package = 'rustc-std-workspace-all compiler_builtins = { version = '0.1.2', optional = true } [features] +default = [] + # Internal feature, only used when building as part of libstd, not part of the # stable interface of this crate. -rustc-dep-of-std = ['core', 'alloc', 'compiler_builtins', 'adler/rustc-dep-of-std'] +rustc-dep-of-std = ['core', 'alloc', 'compiler_builtins', 'adler/rustc-dep-of-std', 'simd-adler32/std'] # This feature has no effect (See Frommi/miniz_oxide#95) no_extern_crate_alloc = [] + +simd = ['simd-adler32'] diff --git a/miniz_oxide/src/shared.rs b/miniz_oxide/src/shared.rs index dcdec958..8b81fb11 100644 --- a/miniz_oxide/src/shared.rs +++ b/miniz_oxide/src/shared.rs @@ -1,5 +1,3 @@ -use adler::Adler32; - #[doc(hidden)] pub const MZ_ADLER32_INIT: u32 = 1; @@ -11,8 +9,17 @@ pub const HUFFMAN_LENGTH_ORDER: [u8; 19] = [ ]; #[doc(hidden)] +#[cfg(not(feature = "simd"))] pub fn update_adler32(adler: u32, data: &[u8]) -> u32 { - let mut hash = Adler32::from_checksum(adler); + let mut hash = adler::Adler32::from_checksum(adler); hash.write_slice(data); hash.checksum() } + +#[doc(hidden)] +#[cfg(feature = "simd")] +pub fn update_adler32(adler: u32, data: &[u8]) -> u32 { + let mut hash = simd_adler32::Adler32::from_checksum(adler); + hash.write(data); + hash.finish() +}