Skip to content

Commit

Permalink
feature(simd): add simd-adler32 behind simd feature flag (#104)
Browse files Browse the repository at this point in the history
thanks
  • Loading branch information
mcountryman committed Apr 25, 2021
1 parent 3db0b43 commit 19782aa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ build_stub_miniz = []
no_c_export = []
libc_stub = []

simd = ['miniz_oxide/simd']

[profile.dev]
panic = "abort"

Expand Down
7 changes: 6 additions & 1 deletion miniz_oxide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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']
13 changes: 10 additions & 3 deletions miniz_oxide/src/shared.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use adler::Adler32;

#[doc(hidden)]
pub const MZ_ADLER32_INIT: u32 = 1;

Expand All @@ -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()
}

0 comments on commit 19782aa

Please sign in to comment.