Skip to content

Commit

Permalink
fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
picoHz committed Oct 26, 2022
1 parent 83820b0 commit 226150a
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 36 deletions.
8 changes: 4 additions & 4 deletions src/lz4/block/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn decompress_safe(src: &[u8], dst: &mut [u8]) -> Result<usize> {
dst.as_mut_ptr() as *mut c_char,
src.len() as c_int,
dst.len() as c_int,
) as i32
)
};
if result < 0 {
Err(Error::new(ErrorKind::DecompressionFailed))
Expand All @@ -81,7 +81,7 @@ pub fn decompress_safe_partial(src: &[u8], dst: &mut [u8], original_size: usize)
src.len() as c_int,
original_size as c_int,
dst.len() as c_int,
) as i32
)
};
if result < 0 {
Err(Error::new(ErrorKind::DecompressionFailed))
Expand All @@ -99,7 +99,7 @@ pub fn decompress_safe_using_dict(src: &[u8], dst: &mut [u8], dict: &[u8]) -> Re
dst.len() as c_int,
dict.as_ptr() as *const c_char,
dict.len() as c_int,
) as i32
)
};
if result < 0 {
Err(Error::new(ErrorKind::DecompressionFailed))
Expand All @@ -123,7 +123,7 @@ pub fn decompress_safe_partial_using_dict(
dst.len() as c_int,
dict.as_ptr() as *const c_char,
dict.len() as c_int,
) as i32
)
};
if result < 0 {
Err(Error::new(ErrorKind::DecompressionFailed))
Expand Down
4 changes: 2 additions & 2 deletions src/lz4/stream/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl CompressionContext {
unsafe {
let ptr = binding::LZ4_initStream(
stream.as_mut_ptr() as *mut c_void,
size_of::<LZ4Stream>() as usize,
size_of::<LZ4Stream>(),
);
if !ptr.is_null() {
return Ok(Self {
Expand Down Expand Up @@ -134,7 +134,7 @@ impl DecompressionContext {
dst as *mut c_char,
src.len() as c_int,
dst_len as c_int,
) as i32
)
};
if result < 0 {
Err(Error::new(ErrorKind::DecompressionFailed))
Expand Down
7 changes: 1 addition & 6 deletions src/lz4_hc/stream/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ impl CompressionContext {
}

pub fn set_favor_dec_speed(&mut self, flag: bool) {
unsafe {
binding::LZ4_favorDecompressionSpeed(
self.stream.as_ptr(),
if flag { 1 } else { 0 } as c_int,
)
}
unsafe { binding::LZ4_favorDecompressionSpeed(self.stream.as_ptr(), i32::from(flag)) }
}

pub fn load_dict(&mut self, dict: &[u8]) {
Expand Down
20 changes: 10 additions & 10 deletions src/lz4f/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl CompressionContext {
} else {
binding::LZ4F_compressBegin(self.ctx.as_ptr(), dst as *mut c_void, dst_len, prefs)
}
} as usize;
};
result_from_code(code).map(|_| code)
}

Expand All @@ -74,7 +74,7 @@ impl CompressionContext {
src.len(),
&opt as *const LZ4FCompressionOptions,
)
} as usize;
};
result_from_code(code).map(|_| code)
}

Expand All @@ -87,7 +87,7 @@ impl CompressionContext {
dst_len,
&opt as *const LZ4FCompressionOptions,
)
} as usize;
};
result_from_code(code).map(|_| code)
}

Expand All @@ -100,12 +100,12 @@ impl CompressionContext {
dst_len,
&opt as *const LZ4FCompressionOptions,
)
} as usize;
};
result_from_code(code).map(|_| code)
}

pub fn compress_bound(src_size: usize, prefs: &Preferences) -> usize {
unsafe { binding::LZ4F_compressBound(src_size as usize, prefs as *const Preferences) }
unsafe { binding::LZ4F_compressBound(src_size, prefs as *const Preferences) }
}
}

Expand Down Expand Up @@ -151,7 +151,7 @@ impl DecompressionContext {
&mut src_len as *mut usize,
)
};
result_from_code(code).map(|_| (unsafe { info.assume_init() }, src_len as usize))
result_from_code(code).map(|_| (unsafe { info.assume_init() }, src_len))
}

pub fn decompress_dict(
Expand All @@ -176,7 +176,7 @@ impl DecompressionContext {
&opt as *const LZ4FDecompressionOptions,
)
};
result_from_code(code).map(|_| (src_len as usize, dst_len as usize, code as usize))
result_from_code(code).map(|_| (src_len, dst_len, code))
}

pub fn reset(&mut self) {
Expand All @@ -195,11 +195,11 @@ impl Drop for DecompressionContext {
}

pub fn compress_frame_bound(src_size: usize, prefs: &Preferences) -> usize {
unsafe { binding::LZ4F_compressFrameBound(src_size as usize, prefs as *const Preferences) }
unsafe { binding::LZ4F_compressFrameBound(src_size, prefs as *const Preferences) }
}

pub fn header_size(src: &[u8]) -> usize {
unsafe { binding::LZ4F_headerSize(src.as_ptr() as *const c_void, src.len()) as usize }
unsafe { binding::LZ4F_headerSize(src.as_ptr() as *const c_void, src.len()) }
}

pub fn compress(src: &[u8], dst: *mut u8, dst_len: usize, prefs: &Preferences) -> Result<usize> {
Expand All @@ -210,7 +210,7 @@ pub fn compress(src: &[u8], dst: *mut u8, dst_len: usize, prefs: &Preferences) -
src.as_ptr() as *const c_void,
src.len(),
prefs as *const Preferences,
) as usize
)
};
result_from_code(code).map(|_| code)
}
Expand Down
4 changes: 2 additions & 2 deletions src/lz4f/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct LZ4FCompressionOptions {
impl LZ4FCompressionOptions {
pub fn stable(stable: bool) -> Self {
Self {
stable_src: if stable { 1 } else { 0 },
stable_src: u32::from(stable),
..Default::default()
}
}
Expand All @@ -45,7 +45,7 @@ pub struct LZ4FDecompressionOptions {
impl LZ4FDecompressionOptions {
pub fn stable(stable: bool) -> Self {
Self {
stable_dst: if stable { 1 } else { 0 },
stable_dst: u32::from(stable),
..Default::default()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lz4f/frame_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl FrameInfo {

/// Returns the dictionary id.
pub const fn dict_id(&self) -> u32 {
self.dict_id as u32
self.dict_id
}

/// Returns the block checksum.
Expand Down
2 changes: 1 addition & 1 deletion src/lz4f/preferences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Preferences {

/// Returns the compression level.
pub const fn compression_level(&self) -> i32 {
self.compression_level as i32
self.compression_level
}

/// Returns the auto flush mode flag.
Expand Down
9 changes: 3 additions & 6 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ fn preferences_set() -> impl Iterator<Item = Preferences> {

pub fn lz4f_test_set() -> impl Iterator<Item = (Bytes, Preferences)> {
generate_data()
.map(|data| preferences_set().map(move |prefs| (data.clone(), prefs)))
.flatten()
.flat_map(|data| preferences_set().map(move |prefs| (data.clone(), prefs)))
}

fn compression_acc_set() -> impl Iterator<Item = i32> {
Expand All @@ -80,8 +79,7 @@ fn compression_acc_set() -> impl Iterator<Item = i32> {

pub fn lz4_test_set() -> impl Iterator<Item = (Bytes, i32)> {
generate_data()
.map(|data| compression_acc_set().map(move |acc| (data.clone(), acc)))
.flatten()
.flat_map(|data| compression_acc_set().map(move |acc| (data.clone(), acc)))
}

pub fn lz4_stream_test_set() -> impl Iterator<Item = (Vec<Bytes>, i32)> {
Expand All @@ -102,8 +100,7 @@ fn compression_level_set() -> impl Iterator<Item = i32> {

pub fn lz4_hc_test_set() -> impl Iterator<Item = (Bytes, i32)> {
generate_data()
.map(|data| compression_level_set().map(move |level| (data.clone(), level)))
.flatten()
.flat_map(|data| compression_level_set().map(move |level| (data.clone(), level)))
}

pub fn lz4_hc_stream_test_set() -> impl Iterator<Item = (Vec<Bytes>, i32)> {
Expand Down
3 changes: 1 addition & 2 deletions tests/lz4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ mod decompress {
#[test]
fn partial() {
lz4_test_set()
.map(|(src, mode)| (0..20).map(move |n| (src.clone(), mode, 16 << n)))
.flatten()
.flat_map(|(src, mode)| (0..20).map(move |n| (src.clone(), mode, 16 << n)))
.par_bridge()
.for_each(|(src, mode, len)| {
let mut comp_buf = Vec::new();
Expand Down
3 changes: 1 addition & 2 deletions tests/lz4_hc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ mod compress_partial {
#[test]
fn default() {
lz4_hc_test_set()
.map(|(src, level)| (0..20).map(move |n| (src.clone(), level, 16 << n)))
.flatten()
.flat_map(|(src, level)| (0..20).map(move |n| (src.clone(), level, 16 << n)))
.par_bridge()
.for_each(|(src, level, len)| {
let mut comp_buf = vec![0; len];
Expand Down

0 comments on commit 226150a

Please sign in to comment.