Skip to content

Commit 5516460

Browse files
brianpanefolkertdev
authored andcommitted
Make State::max_chain_length u16
1 parent 8d99c52 commit 5516460

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

zlib-rs/src/deflate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ fn lm_set_level(state: &mut State, level: i8) {
797797
state.max_lazy_match = CONFIGURATION_TABLE[level as usize].max_lazy as usize;
798798
state.good_match = CONFIGURATION_TABLE[level as usize].good_length as usize;
799799
state.nice_match = CONFIGURATION_TABLE[level as usize].nice_length as usize;
800-
state.max_chain_length = CONFIGURATION_TABLE[level as usize].max_chain as usize;
800+
state.max_chain_length = CONFIGURATION_TABLE[level as usize].max_chain;
801801

802802
state.hash_calc_variant = HashCalcVariant::for_max_chain_length(state.max_chain_length);
803803
state.level = level;
@@ -813,7 +813,7 @@ pub fn tune(
813813
stream.state.good_match = good_length;
814814
stream.state.max_lazy_match = max_lazy;
815815
stream.state.nice_match = nice_length;
816-
stream.state.max_chain_length = max_chain;
816+
stream.state.max_chain_length = max_chain as u16;
817817

818818
ReturnCode::Ok
819819
}
@@ -1263,7 +1263,7 @@ pub(crate) struct State<'a> {
12631263

12641264
/// To speed up deflation, hash chains are never searched beyond this length.
12651265
/// A higher limit improves compression ratio but degrades the speed.
1266-
pub(crate) max_chain_length: usize,
1266+
pub(crate) max_chain_length: u16,
12671267

12681268
// TODO untangle this mess! zlib uses the same field differently based on compression level
12691269
// we should just have 2 fields for clarity!

zlib-rs/src/deflate/hash_calc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub enum HashCalcVariant {
99
impl HashCalcVariant {
1010
/// Use rolling hash for deflate_slow algorithm with level 9. It allows us to
1111
/// properly lookup different hash chains to speed up longest_match search.
12-
pub fn for_max_chain_length(max_chain_length: usize) -> Self {
12+
pub fn for_max_chain_length(max_chain_length: u16) -> Self {
1313
if max_chain_length > 1024 {
1414
HashCalcVariant::Roll
1515
} else {

zlib-rs/src/deflate/longest_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn longest_match_help<const SLOW: bool>(
2626
let limit_base: Pos;
2727
let early_exit: bool;
2828

29-
let mut chain_length: usize;
29+
let mut chain_length: u16;
3030
let mut best_len: usize;
3131

3232
let lookahead = state.lookahead;

0 commit comments

Comments
 (0)