Skip to content

Commit 4c71540

Browse files
committed
simplify quick match matching
1 parent 076242a commit 4c71540

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

Diff for: zlib-rs/src/deflate/algorithm/quick.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,15 @@ pub fn deflate_quick(stream: &mut DeflateStream, flush: DeflateFlush) -> BlockSt
9797
let dist = state.strstart as isize - hash_head as isize;
9898

9999
if dist <= state.max_dist() as isize && dist > 0 {
100-
let str_start = &state.window.filled()[state.strstart..];
101-
let match_start = &state.window.filled()[hash_head as usize..];
100+
let str_start = &state.window.filled()[state.strstart..][..258];
101+
let match_start = &state.window.filled()[hash_head as usize..][..258];
102102

103-
macro_rules! first_two_bytes {
104-
($slice:expr, $offset:expr) => {
105-
u16::from_le_bytes($slice[$offset..$offset + 2].try_into().unwrap())
106-
};
107-
}
103+
let (prefix1, tail1) = str_start.split_at(2);
104+
let (prefix2, tail2) = match_start.split_at(2);
108105

109-
if first_two_bytes!(str_start, 0) == first_two_bytes!(match_start, 0) {
110-
let mut match_len = crate::deflate::compare256::compare256_slice(
111-
&str_start[2..],
112-
&match_start[2..],
113-
) + 2;
106+
if prefix1 == prefix2 {
107+
let mut match_len =
108+
2 + crate::deflate::compare256::compare256_slice(tail1, tail2);
114109

115110
if match_len >= WANT_MIN_MATCH {
116111
match_len = Ord::min(match_len, state.lookahead);

Diff for: zlib-rs/src/deflate/compare256.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ pub fn compare256_slice(src0: &[u8], src1: &[u8]) -> usize {
1717
#[inline(always)]
1818
fn compare256(src0: &[u8; 256], src1: &[u8; 256]) -> usize {
1919
#[cfg(target_feature = "avx2")]
20-
return avx2::compare256(src0, src1);
20+
return unsafe { avx2::compare256(src0, src1) };
2121

2222
#[cfg(target_feature = "neon")]
23-
return neon::compare256(src0, src1);
23+
return unsafe { neon::compare256(src0, src1) };
2424

2525
#[cfg(target_feature = "simd128")]
26-
return wasm32::compare256(src0, src1);
26+
return unsafe { wasm32::compare256(src0, src1) };
2727

2828
#[allow(unreachable_code)]
2929
compare256_via_function_pointer(src0, src1)

0 commit comments

Comments
 (0)