Skip to content

Commit 4e432fd

Browse files
committed
simplify quick match matching
1 parent bc8a692 commit 4e432fd

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
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);

0 commit comments

Comments
 (0)