Skip to content

Commit 1f37a0d

Browse files
committed
deflate::Window: cleanup unused fields
1 parent 0478c9e commit 1f37a0d

File tree

2 files changed

+3
-39
lines changed

2 files changed

+3
-39
lines changed

zlib-rs/src/deflate.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,6 @@ pub(crate) fn read_buf_window(stream: &mut DeflateStream, offset: usize, size: u
16501650
// we likely cannot fuse the crc32 and the copy here because the input can be changed by
16511651
// a concurrent thread. Therefore it cannot be converted into a slice!
16521652
let window = &mut stream.state.window;
1653-
window.initialize_at_least(offset + len);
16541653
// SAFETY: len is bounded by avail_in, so this copy is in bounds.
16551654
unsafe { window.copy_and_initialize(offset..offset + len, stream.next_in) };
16561655

@@ -1660,15 +1659,13 @@ pub(crate) fn read_buf_window(stream: &mut DeflateStream, offset: usize, size: u
16601659
// we likely cannot fuse the adler32 and the copy here because the input can be changed by
16611660
// a concurrent thread. Therefore it cannot be converted into a slice!
16621661
let window = &mut stream.state.window;
1663-
window.initialize_at_least(offset + len);
16641662
// SAFETY: len is bounded by avail_in, so this copy is in bounds.
16651663
unsafe { window.copy_and_initialize(offset..offset + len, stream.next_in) };
16661664

16671665
let data = &stream.state.window.filled()[offset..][..len];
16681666
stream.adler = adler32(stream.adler as u32, data) as _;
16691667
} else {
16701668
let window = &mut stream.state.window;
1671-
window.initialize_at_least(offset + len);
16721669
// SAFETY: len is bounded by avail_in, so this copy is in bounds.
16731670
unsafe { window.copy_and_initialize(offset..offset + len, stream.next_in) };
16741671
}
@@ -1742,7 +1739,6 @@ pub(crate) fn fill_window(stream: &mut DeflateStream) {
17421739
// explicitly initialize them with zeros.
17431740
//
17441741
// see also the "fill_window_out_of_bounds" test.
1745-
state.window.initialize_at_least(2 * wsize);
17461742
state.window.filled_mut().copy_within(wsize..2 * wsize, 0);
17471743

17481744
if state.match_start >= wsize {
@@ -1811,11 +1807,6 @@ pub(crate) fn fill_window(stream: &mut DeflateStream) {
18111807
}
18121808
}
18131809

1814-
// initialize some memory at the end of the (filled) window, so SIMD operations can go "out of
1815-
// bounds" without violating any requirements. The window allocation is already slightly bigger
1816-
// to allow for this.
1817-
stream.state.window.initialize_out_of_bounds();
1818-
18191810
assert!(
18201811
stream.state.strstart <= stream.state.window_size - MIN_LOOKAHEAD,
18211812
"not enough room for search"

zlib-rs/src/deflate/window.rs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ pub struct Window<'a> {
66
// perform bounds checks.
77
buf: WeakSliceMut<'a, u8>,
88

9-
// number of initialized bytes
10-
filled: usize,
11-
129
window_bits: usize,
13-
14-
high_water: usize,
1510
}
1611

1712
impl<'a> Window<'a> {
@@ -21,12 +16,7 @@ impl<'a> Window<'a> {
2116
// SAFETY: freshly allocated buffer
2217
let buf = unsafe { WeakSliceMut::from_raw_parts_mut(ptr, len) };
2318

24-
Some(Self {
25-
buf,
26-
filled: len,
27-
window_bits,
28-
high_water: len,
29-
})
19+
Some(Self { buf, window_bits })
3020
}
3121

3222
pub fn clone_in(&self, alloc: &Allocator<'a>) -> Option<Self> {
@@ -36,8 +26,6 @@ impl<'a> Window<'a> {
3626
.buf
3727
.as_mut_slice()
3828
.copy_from_slice(self.buf.as_slice());
39-
clone.filled = self.filled;
40-
clone.high_water = self.high_water;
4129

4230
Some(clone)
4331
}
@@ -60,14 +48,14 @@ impl<'a> Window<'a> {
6048
#[inline]
6149
pub fn filled(&self) -> &[u8] {
6250
// SAFETY: `self.buf` has been initialized for at least `filled` elements
63-
unsafe { core::slice::from_raw_parts(self.buf.as_ptr().cast(), self.filled) }
51+
unsafe { core::slice::from_raw_parts(self.buf.as_ptr().cast(), self.buf.len()) }
6452
}
6553

6654
/// Returns a mutable reference to the filled portion of the buffer.
6755
#[inline]
6856
pub fn filled_mut(&mut self) -> &mut [u8] {
6957
// SAFETY: `self.buf` has been initialized for at least `filled` elements
70-
unsafe { core::slice::from_raw_parts_mut(self.buf.as_mut_ptr().cast(), self.filled) }
58+
unsafe { core::slice::from_raw_parts_mut(self.buf.as_mut_ptr().cast(), self.buf.len()) }
7159
}
7260

7361
/// # Safety
@@ -78,23 +66,8 @@ impl<'a> Window<'a> {
7866

7967
let dst = self.buf.as_mut_slice()[range].as_mut_ptr() as *mut u8;
8068
unsafe { core::ptr::copy_nonoverlapping(src, dst, end - start) };
81-
82-
if start >= self.filled {
83-
self.filled = Ord::max(self.filled, end);
84-
}
85-
86-
self.high_water = Ord::max(self.high_water, self.filled);
8769
}
8870

89-
// this library has many functions that operated in a chunked fashion on memory. For
90-
// performance, we want to minimize bounds checks. Therefore we reserve initialize some extra
91-
// memory at the end of the window so that chunked operations can use the whole buffer. If they
92-
// go slightly over `self.capacity` that's okay, we account for that here by making sure the
93-
// memory there is initialized!
94-
pub fn initialize_out_of_bounds(&mut self) {}
95-
96-
pub fn initialize_at_least(&mut self, at_least: usize) {}
97-
9871
// padding required so that SIMD operations going out-of-bounds are not a problem
9972
pub fn padding() -> usize {
10073
if crate::cpu_features::is_enabled_pclmulqdq() {

0 commit comments

Comments
 (0)