usecrate::allocate::Allocator; use core::mem::MaybeUninit;
#[derive(Debug)] pubstruct Window<'a> { // the full window allocation. This is longer than w_size so that operations don't need to // perform bounds checks.
buf: &'a mut [MaybeUninit<u8>],
/// Returns a shared reference to the filled portion of the buffer. #[inline] pubfn filled(&self) -> &[u8] { // safety: `self.buf` has been initialized for at least `filled` elements unsafe { core::slice::from_raw_parts(self.buf.as_ptr().cast(), self.filled) }
}
/// Returns a mutable reference to the filled portion of the buffer. #[inline] pubfn filled_mut(&mutself) -> &mut [u8] { // safety: `self.buf` has been initialized for at least `filled` elements unsafe { core::slice::from_raw_parts_mut(self.buf.as_mut_ptr().cast(), self.filled) }
}
/// # Safety /// /// `src` must point to `range.end - range.start` valid (initialized!) bytes pubunsafefn copy_and_initialize(&mutself, range: core::ops::Range<usize>, src: *const u8) { let (start, end) = (range.start, range.end);
let dst = self.buf[range].as_mut_ptr() as *mut u8;
core::ptr::copy_nonoverlapping(src, dst, end - start);
if start >= self.filled { self.filled = Ord::max(self.filled, end);
}
// this library has many functions that operated in a chunked fashion on memory. For // performance, we want to minimize bounds checks. Therefore we reserve initialize some extra // memory at the end of the window so that chunked operations can use the whole buffer. If they // go slightly over `self.capacity` that's okay, we account for that here by making sure the // memory there is initialized! pubfn initialize_out_of_bounds(&mutself) { const WIN_INIT: usize = crate::deflate::STD_MAX_MATCH;
// If the WIN_INIT bytes after the end of the current data have never been // written, then zero those bytes in order to avoid memory check reports of // the use of uninitialized (or uninitialised as Julian writes) bytes by // the longest match routines. Update the high water mark for the next // time through here. WIN_INIT is set to STD_MAX_MATCH since the longest match // routines allow scanning to strstart + STD_MAX_MATCH, ignoring lookahead. ifself.high_water < self.capacity() { let curr = self.filled().len();
ifself.high_water < curr { // Previous high water mark below current data -- zero WIN_INIT // bytes or up to end of window, whichever is less. let init = Ord::min(self.capacity() - curr, WIN_INIT);
self.filled += init;
} elseifself.high_water < curr + WIN_INIT { // High water mark at or above current data, but below current data // plus WIN_INIT -- zero out to current data plus WIN_INIT, or up // to end of window, whichever is less. let init = Ord::min(
curr + WIN_INIT - self.high_water, self.capacity() - self.high_water,
);
pubfn initialize_at_least(&mutself, at_least: usize) { let end = at_least.clamp(self.high_water, self.buf.len()); self.buf[self.high_water..end].fill(MaybeUninit::new(0));
self.high_water = end; self.filled = end;
}
// padding required so that SIMD operations going out-of-bounds are not a problem pubfn padding() -> usize { ifcrate::cpu_features::is_enabled_pclmulqdq() { 8
} else { 0
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-06-18)
¤
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.