have: usize, // number of bytes logically written to the window. this can be higher than // buf.len() if we run out of space in the window
next: usize, // write head
}
/// The size of the underlying buffer. For inflate, use `size` instead. This function is used /// in `inflateBack` which does not consider the padding. pubfn buffer_size(&self) -> usize {
assert!(self.buf.len().is_power_of_two()); self.buf.len()
}
pubfn size(&self) -> usize { // `self.len == 0` is used for uninitialized buffers
assert!(self.buf.is_empty() || self.buf.len() >= Self::padding()); self.buf.len().saturating_sub(Self::padding())
}
/// number of bytes in the window. Saturates at `Self::capacity`. pubfn have(&self) -> usize { self.have
}
pub(crate) fn extend(
&mutself,
slice: &[u8],
flags: i32,
update_checksum: bool,
checksum: &mut u32,
crc_fold: &mut Crc32Fold,
) { let len = slice.len(); let wsize = self.size();
if len >= wsize { // We have to split the checksum over non-copied and copied bytes let pos = len.saturating_sub(self.size()); let (non_window_slice, window_slice) = slice.split_at(pos);
// the end part goes onto the end of the window. The start part wraps around and is // written to the start of the window. let (end_part, start_part) = slice.split_at(dist);
if update_checksum { let dst = &mutself.buf.as_mut_slice()[self.next..][..end_part.len()]; if flags != 0 {
crc_fold.fold_copy(dst, end_part);
} else {
*checksum = adler32_fold_copy(*checksum, dst, end_part);
}
} else { self.buf.as_mut_slice()[self.next..][..end_part.len()].copy_from_slice(end_part);
}
if !start_part.is_empty() { let dst = &mutself.buf.as_mut_slice()[..start_part.len()];
#[test] fn window_init() { let window = init_window(2);
assert_eq!(window.size(), 4);
assert_eq!(window.have(), 0);
assert!(!window.is_empty()); let start = window.as_ptr(); let size = window.size(); let (ptr, len) = window.into_raw_parts();
assert_eq!(ptr.cast_const(), start);
assert!(len >= size); // >= because the impl is allowed to add padding to the internal buffer
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.7Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.