Skip to content

Commit b800000

Browse files
brianpanefolkertdev
authored andcommitted
Make State::max_lazy_match u16
1 parent 5516460 commit b800000

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

zlib-rs/src/deflate.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ pub fn init(stream: &mut z_stream, config: DeflateConfig) -> ReturnCode {
376376
_cache_line_3: (),
377377
_padding_0: 0,
378378
_padding_1: 0,
379+
_padding_2: 0,
379380
};
380381

381382
unsafe { state_allocation.as_ptr().write(state) }; // FIXME: write is stable for NonNull since 1.80.0
@@ -680,6 +681,7 @@ pub fn copy<'a>(
680681
_cache_line_3: (),
681682
_padding_0: source_state._padding_0,
682683
_padding_1: source_state._padding_1,
684+
_padding_2: source_state._padding_2,
683685
};
684686

685687
// write the cloned state into state_ptr
@@ -794,7 +796,7 @@ fn lm_init(state: &mut State) {
794796
}
795797

796798
fn lm_set_level(state: &mut State, level: i8) {
797-
state.max_lazy_match = CONFIGURATION_TABLE[level as usize].max_lazy as usize;
799+
state.max_lazy_match = CONFIGURATION_TABLE[level as usize].max_lazy;
798800
state.good_match = CONFIGURATION_TABLE[level as usize].good_length as usize;
799801
state.nice_match = CONFIGURATION_TABLE[level as usize].nice_length as usize;
800802
state.max_chain_length = CONFIGURATION_TABLE[level as usize].max_chain;
@@ -811,7 +813,7 @@ pub fn tune(
811813
max_chain: usize,
812814
) -> ReturnCode {
813815
stream.state.good_match = good_length;
814-
stream.state.max_lazy_match = max_lazy;
816+
stream.state.max_lazy_match = max_lazy as u16;
815817
stream.state.nice_match = nice_length;
816818
stream.state.max_chain_length = max_chain as u16;
817819

@@ -1274,7 +1276,9 @@ pub(crate) struct State<'a> {
12741276
// define max_insert_length max_lazy_match
12751277
/// Attempt to find a better match only when the current match is strictly smaller
12761278
/// than this value. This mechanism is used only for compression levels >= 4.
1277-
pub(crate) max_lazy_match: usize,
1279+
pub(crate) max_lazy_match: u16,
1280+
1281+
_padding_2: usize,
12781282

12791283
/// Window position at the beginning of the current output block. Gets
12801284
/// negative when the window is moved backwards.
@@ -1399,7 +1403,7 @@ impl<'a> State<'a> {
13991403
// TODO untangle this mess! zlib uses the same field differently based on compression level
14001404
// we should just have 2 fields for clarity!
14011405
pub(crate) fn max_insert_length(&self) -> usize {
1402-
self.max_lazy_match
1406+
self.max_lazy_match as usize
14031407
}
14041408

14051409
/// Total size of the pending buf. But because `pending` shares memory with `sym_buf`, this is

zlib-rs/src/deflate/algorithm/slow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn deflate_slow(stream: &mut DeflateStream, flush: DeflateFlush) -> BlockSta
5454
dist = state.strstart as isize - hash_head as isize;
5555

5656
if valid_distance_range.contains(&dist)
57-
&& state.prev_length < state.max_lazy_match
57+
&& state.prev_length < state.max_lazy_match as usize
5858
&& hash_head != 0
5959
{
6060
// To simplify the code, we prevent matches with the string

0 commit comments

Comments
 (0)