Skip to content

Commit eb25760

Browse files
brianpanefolkertdev
authored andcommitted
Make State::nice_length u16
1 parent b800000 commit eb25760

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

zlib-rs/src/deflate.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,10 @@ pub fn init(stream: &mut z_stream, config: DeflateConfig) -> ReturnCode {
374374
_cache_line_1: (),
375375
_cache_line_2: (),
376376
_cache_line_3: (),
377-
_padding_0: 0,
377+
_padding_0: [0; 14],
378378
_padding_1: 0,
379379
_padding_2: 0,
380+
_padding_3: [0; 6],
380381
};
381382

382383
unsafe { state_allocation.as_ptr().write(state) }; // FIXME: write is stable for NonNull since 1.80.0
@@ -682,6 +683,7 @@ pub fn copy<'a>(
682683
_padding_0: source_state._padding_0,
683684
_padding_1: source_state._padding_1,
684685
_padding_2: source_state._padding_2,
686+
_padding_3: source_state._padding_3,
685687
};
686688

687689
// write the cloned state into state_ptr
@@ -797,8 +799,8 @@ fn lm_init(state: &mut State) {
797799

798800
fn lm_set_level(state: &mut State, level: i8) {
799801
state.max_lazy_match = CONFIGURATION_TABLE[level as usize].max_lazy;
800-
state.good_match = CONFIGURATION_TABLE[level as usize].good_length as usize;
801-
state.nice_match = CONFIGURATION_TABLE[level as usize].nice_length as usize;
802+
state.good_match = CONFIGURATION_TABLE[level as usize].good_length;
803+
state.nice_match = CONFIGURATION_TABLE[level as usize].nice_length;
802804
state.max_chain_length = CONFIGURATION_TABLE[level as usize].max_chain;
803805

804806
state.hash_calc_variant = HashCalcVariant::for_max_chain_length(state.max_chain_length);
@@ -812,9 +814,9 @@ pub fn tune(
812814
nice_length: usize,
813815
max_chain: usize,
814816
) -> ReturnCode {
815-
stream.state.good_match = good_length;
817+
stream.state.good_match = good_length as u16;
816818
stream.state.max_lazy_match = max_lazy as u16;
817-
stream.state.nice_match = nice_length;
819+
stream.state.nice_match = nice_length as u16;
818820
stream.state.max_chain_length = max_chain as u16;
819821

820822
ReturnCode::Ok
@@ -1243,16 +1245,17 @@ pub(crate) struct State<'a> {
12431245
bit_writer: BitWriter<'a>,
12441246

12451247
/// Use a faster search when the previous match is longer than this
1246-
pub(crate) good_match: usize,
1248+
pub(crate) good_match: u16,
1249+
_padding_3: [u8; 6],
12471250

12481251
_cache_line_0: (),
12491252

12501253
/// Stop searching when current match exceeds this
1251-
pub(crate) nice_match: usize,
1254+
pub(crate) nice_match: u16,
12521255

12531256
// Padding to maintain the grouping of fields into cache lines during refactoring
12541257
// FIXME find a real field to swap into this location after the overall layout is optimized.
1255-
_padding_0: usize,
1258+
_padding_0: [u8; 14],
12561259

12571260
pub(crate) strstart: usize, /* start of string to insert */
12581261
pub(crate) match_start: Pos, /* start of matching string */

zlib-rs/src/deflate/longest_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn longest_match_help<const SLOW: bool>(
7171

7272
// Don't waste too much time by following a chain if we already have a good match
7373
chain_length = state.max_chain_length;
74-
if best_len >= state.good_match {
74+
if best_len >= state.good_match as usize {
7575
chain_length >>= 2;
7676
}
7777
let nice_match = state.nice_match;
@@ -242,7 +242,7 @@ fn longest_match_help<const SLOW: bool>(
242242
return (lookahead, match_start);
243243
}
244244
best_len = len;
245-
if best_len >= nice_match {
245+
if best_len >= nice_match as usize {
246246
return (best_len, match_start);
247247
}
248248

0 commit comments

Comments
 (0)