Skip to content

Commit b26519a

Browse files
brianpanefolkertdev
authored andcommitted
Remove the cloning of scan_start & scan_end in longest_match_help
1 parent 4ae3517 commit b26519a

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

zlib-rs/src/deflate/longest_match.rs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ fn longest_match_help<const SLOW: bool>(
4848
let lookahead = state.lookahead;
4949
let mut match_offset = 0;
5050

51-
let mut scan_start = [0u8; 8];
52-
let mut scan_end = [0u8; 8];
53-
5451
macro_rules! goto_next_in_chain {
5552
() => {
5653
chain_length -= 1;
@@ -84,16 +81,8 @@ fn longest_match_help<const SLOW: bool>(
8481
}
8582
}
8683

87-
if UNALIGNED64_OK {
88-
scan_start.copy_from_slice(&scan[..core::mem::size_of::<u64>()]);
89-
scan_end.copy_from_slice(&scan[offset..][..core::mem::size_of::<u64>()]);
90-
} else if UNALIGNED_OK {
91-
scan_start[..4].copy_from_slice(&scan[..core::mem::size_of::<u32>()]);
92-
scan_end[..4].copy_from_slice(&scan[offset..][..core::mem::size_of::<u32>()]);
93-
} else {
94-
scan_start[..2].copy_from_slice(&scan[..core::mem::size_of::<u16>()]);
95-
scan_end[..2].copy_from_slice(&scan[offset..][..core::mem::size_of::<u16>()]);
96-
}
84+
let scan_start = window[strstart..].as_ptr();
85+
let mut scan_end = window[strstart + offset..].as_ptr();
9786

9887
let mut mbase_start = window.as_ptr();
9988
let mut mbase_end = window[offset..].as_ptr();
@@ -208,9 +197,6 @@ fn longest_match_help<const SLOW: bool>(
208197
// this loop also breaks before cur_match gets past strstart, which is bounded by
209198
// window_size - MIN_LOOKAHEAD, so 8 byte reads of mbase_end/start are in-bounds.
210199
unsafe {
211-
let scan_start = scan_start.as_ptr();
212-
let scan_end = scan_end.as_ptr();
213-
214200
if UNALIGNED_OK {
215201
if best_len < core::mem::size_of::<u32>() {
216202
loop {
@@ -289,13 +275,7 @@ fn longest_match_help<const SLOW: bool>(
289275
}
290276
}
291277

292-
if UNALIGNED64_OK {
293-
scan_end.copy_from_slice(&scan[offset..][..core::mem::size_of::<u64>()]);
294-
} else if UNALIGNED_OK {
295-
scan_end[..4].copy_from_slice(&scan[offset..][..core::mem::size_of::<u32>()]);
296-
} else {
297-
scan_end[..2].copy_from_slice(&scan[offset..][..core::mem::size_of::<u16>()]);
298-
}
278+
scan_end = window[strstart + offset..].as_ptr();
299279

300280
// Look for a better string offset
301281
if SLOW && len > STD_MIN_MATCH && match_start + len < strstart {

0 commit comments

Comments
 (0)