Skip to content

Commit

Permalink
cleanup Writer api usage
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Sep 17, 2024
1 parent 6928cc0 commit 5601333
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
17 changes: 7 additions & 10 deletions zlib-rs/src/inflate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,10 +887,11 @@ impl<'a> State<'a> {
ReturnCode::StreamError
}

#[inline(always)]
fn lit(&mut self) -> ReturnCode {
if self.writer.remaining() == 0 {
if self.writer.is_full() {
#[cfg(all(test, feature = "std"))]
eprintln!("Ok: read_buf is full ({} bytes)", self.writer.capacity());
eprintln!("Ok: writer is full ({} bytes)", self.writer.capacity());
return self.inflate_leave(ReturnCode::Ok);
}

Expand Down Expand Up @@ -1236,22 +1237,18 @@ impl<'a> State<'a> {
}

/// copy match from window to output

fn match_(&mut self) -> ReturnCode {
if self.writer.remaining() == 0 {
if self.writer.is_full() {
#[cfg(all(feature = "std", test))]
eprintln!(
"BufError: read_buf is full ({} bytes)",
"BufError: writer is full ({} bytes)",
self.writer.capacity()
);
return self.inflate_leave(ReturnCode::Ok);
}

// this is not quite right. not sure when that matters
let out = self.writer.remaining() + self.writer.len();
let left = self.writer.remaining();

let copy = out - left;
let copy = self.writer.len();

let copy = if self.offset > copy {
// copy from window to output
Expand Down Expand Up @@ -1285,7 +1282,7 @@ impl<'a> State<'a> {

copy
} else {
let copy = Ord::min(self.length, self.writer.remaining());
let copy = Ord::min(self.length, left);
self.writer.copy_match(self.offset, copy);

copy
Expand Down
5 changes: 5 additions & 0 deletions zlib-rs/src/inflate/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ impl<'a> Writer<'a> {
self.capacity() - self.filled
}

#[inline]
pub fn is_full(&self) -> bool {
self.filled == self.buf.len()
}

pub fn push(&mut self, byte: u8) {
self.buf[self.filled] = MaybeUninit::new(byte);

Expand Down

0 comments on commit 5601333

Please sign in to comment.