Skip to content

Commit e5a7487

Browse files
committed
Don't box compression/decompression type and avoid indirections and allocs
1 parent f47f3e4 commit e5a7487

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

gix-features/src/zlib/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::ffi::c_int;
22

33
/// A type to hold all state needed for decompressing a ZLIB encoded stream.
4-
pub struct Decompress(Box<libz_rs_sys::z_stream>);
4+
pub struct Decompress(libz_rs_sys::z_stream);
55

66
unsafe impl Sync for Decompress {}
77
unsafe impl Send for Decompress {}
@@ -25,11 +25,11 @@ impl Decompress {
2525

2626
/// Create a new instance. Note that it allocates in various ways and thus should be re-used.
2727
pub fn new() -> Self {
28-
let mut this = Box::new(libz_rs_sys::z_stream::default());
28+
let mut this = libz_rs_sys::z_stream::default();
2929

3030
unsafe {
3131
libz_rs_sys::inflateInit_(
32-
&mut *this,
32+
&mut this,
3333
libz_rs_sys::zlibVersion(),
3434
core::mem::size_of::<libz_rs_sys::z_stream>() as core::ffi::c_int,
3535
);
@@ -40,7 +40,7 @@ impl Decompress {
4040

4141
/// Reset the state to allow handling a new stream.
4242
pub fn reset(&mut self) {
43-
unsafe { libz_rs_sys::inflateReset(&mut *self.0) };
43+
unsafe { libz_rs_sys::inflateReset(&mut self.0) };
4444
}
4545

4646
/// Decompress `input` and write all decompressed bytes into `output`, with `flush` defining some details about this.
@@ -56,7 +56,7 @@ impl Decompress {
5656
self.0.next_in = input.as_ptr();
5757
self.0.next_out = output.as_mut_ptr();
5858

59-
match unsafe { libz_rs_sys::inflate(&mut *self.0, flush as _) } {
59+
match unsafe { libz_rs_sys::inflate(&mut self.0, flush as _) } {
6060
libz_rs_sys::Z_OK => Ok(Status::Ok),
6161
libz_rs_sys::Z_BUF_ERROR => Ok(Status::BufError),
6262
libz_rs_sys::Z_STREAM_END => Ok(Status::StreamEnd),
@@ -71,7 +71,7 @@ impl Decompress {
7171

7272
impl Drop for Decompress {
7373
fn drop(&mut self) {
74-
unsafe { libz_rs_sys::inflateEnd(&mut *self.0) };
74+
unsafe { libz_rs_sys::inflateEnd(&mut self.0) };
7575
}
7676
}
7777

gix-features/src/zlib/stream/deflate/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ where
2626
}
2727

2828
/// Hold all state needed for compressing data.
29-
pub struct Compress(Box<libz_rs_sys::z_stream>);
29+
pub struct Compress(libz_rs_sys::z_stream);
3030

3131
unsafe impl Sync for Compress {}
3232
unsafe impl Send for Compress {}
@@ -50,11 +50,11 @@ impl Compress {
5050

5151
/// Create a new instance - this allocates so should be done with care.
5252
pub fn new() -> Self {
53-
let mut this = Box::new(libz_rs_sys::z_stream::default());
53+
let mut this = libz_rs_sys::z_stream::default();
5454

5555
unsafe {
5656
libz_rs_sys::deflateInit_(
57-
&mut *this,
57+
&mut this,
5858
libz_rs_sys::Z_BEST_SPEED,
5959
libz_rs_sys::zlibVersion(),
6060
core::mem::size_of::<libz_rs_sys::z_stream>() as core::ffi::c_int,
@@ -66,7 +66,7 @@ impl Compress {
6666

6767
/// Prepare the instance for a new stream.
6868
pub fn reset(&mut self) {
69-
unsafe { libz_rs_sys::deflateReset(&mut *self.0) };
69+
unsafe { libz_rs_sys::deflateReset(&mut self.0) };
7070
}
7171

7272
/// Compress `input` and write compressed bytes to `output`, with `flush` controlling additional characteristics.
@@ -77,7 +77,7 @@ impl Compress {
7777
self.0.next_in = input.as_ptr();
7878
self.0.next_out = output.as_mut_ptr();
7979

80-
match unsafe { libz_rs_sys::deflate(&mut *self.0, flush as _) } {
80+
match unsafe { libz_rs_sys::deflate(&mut self.0, flush as _) } {
8181
libz_rs_sys::Z_OK => Ok(Status::Ok),
8282
libz_rs_sys::Z_BUF_ERROR => Ok(Status::BufError),
8383
libz_rs_sys::Z_STREAM_END => Ok(Status::StreamEnd),
@@ -91,7 +91,7 @@ impl Compress {
9191

9292
impl Drop for Compress {
9393
fn drop(&mut self) {
94-
unsafe { libz_rs_sys::deflateEnd(&mut *self.0) };
94+
unsafe { libz_rs_sys::deflateEnd(&mut self.0) };
9595
}
9696
}
9797

0 commit comments

Comments
 (0)