Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions zlib-rs/src/deflate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ pub fn init(stream: &mut z_stream, config: DeflateConfig) -> ReturnCode {
_cache_line_1: (),
_cache_line_2: (),
_cache_line_3: (),
_padding_0: 0,
};

unsafe { state_allocation.as_ptr().write(state) }; // FIXME: write is stable for NonNull since 1.80.0
Expand Down Expand Up @@ -676,6 +677,7 @@ pub fn copy<'a>(
_cache_line_1: (),
_cache_line_2: (),
_cache_line_3: (),
_padding_0: source_state._padding_0,
};

// write the cloned state into state_ptr
Expand Down Expand Up @@ -1281,6 +1283,12 @@ pub(crate) struct State<'a> {
/// than this value. This mechanism is used only for compression levels >= 4.
pub(crate) max_lazy_match: u16,

/// number of string matches in current block
/// NOTE: this is a saturating 8-bit counter, to help keep the struct compact. The code that
/// makes decisions based on this field only cares whether the count is greater than 2, so
/// an 8-bit counter is sufficient.
pub(crate) matches: u8,

/// Window position at the beginning of the current output block. Gets
/// negative when the window is moved backwards.
pub(crate) block_start: isize,
Expand Down Expand Up @@ -1315,9 +1323,6 @@ pub(crate) struct State<'a> {

_cache_line_2: (),

/// number of string matches in current block
pub(crate) matches: usize,

/// bit length of current block with optimal trees
opt_len: usize,
/// bit length of current block with static trees
Expand All @@ -1334,6 +1339,8 @@ pub(crate) struct State<'a> {
gzhead: Option<&'a mut gz_header>,
gzindex: usize,

_padding_0: usize,

_cache_line_3: (),

crc_fold: crate::crc32::Crc32Fold,
Expand Down Expand Up @@ -1457,7 +1464,7 @@ impl<'a> State<'a> {
pub(crate) fn tally_dist(&mut self, mut dist: usize, len: usize) -> bool {
self.sym_buf.push_dist(dist as u16, len as u8);

self.matches += 1;
self.matches = self.matches.saturating_add(1);
dist -= 1;

assert!(
Expand Down
Loading