Skip to content

Commit

Permalink
add coments
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev authored and rnijveld committed Jun 10, 2024
1 parent 8eb4265 commit 12d95fb
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions zlib-rs/src/inflate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1604,36 +1604,46 @@ fn inflate_fast_help(state: &mut State, _start: usize) -> ReturnCode {
}

let mut op = dist as usize - written;
let mut from = 0;
let mut from;

let window_next = state.window.next();

if window_next == 0 {
from += window_size - op;
// This case is hit when the window has just wrapped around
// by logic in `Window::extend`. It is special-cased because
// apparently this is quite common.
//
// the match is at the end of the window, even though the next
// position has now wrapped around.
from = window_size - op;
} else if window_next >= op {
from += window_next - op;
// the standard case: a contiguous copy from the window, no wrapping
from = window_next - op;
} else {
// This case is hit when the window has recently wrapped around
// by logic in `Window::extend`.
//
// The match is (partially) at the end of the window
op -= window_next;
from += window_size - op;
from = window_size - op;

if op < len as usize {
// This case is hit when part of the match is at the end of the
// window, and part of it has wrapped around to the start. Copy
// the end section here, the start section will be copied below.
len -= op as u16;
writer.extend(&state.window.as_slice()[from..][..op]);
from = 0;
op = window_next;
}
}

// may need some bytes from the output
if op < len as usize {
let mut len = len as usize;
len -= op;

writer.extend(&state.window.as_slice()[from..][..op]);
let copy = Ord::min(op, len as usize);
writer.extend(&state.window.as_slice()[from..][..copy]);

writer.copy_match(dist as usize, len);
} else {
writer.extend(&state.window.as_slice()[from..][..len as usize]);
if op < len as usize {
// here we need some bytes from the output itself
writer.copy_match(dist as usize, len as usize - op);
}
} else if extra_safe {
todo!()
Expand Down

0 comments on commit 12d95fb

Please sign in to comment.