Skip to content

Commit

Permalink
Merge branch 'PSeitz:main' into uns
Browse files Browse the repository at this point in the history
  • Loading branch information
krasimirgg authored Mar 19, 2024
2 parents d3f60a2 + 06f9c9a commit 566d29f
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 18 deletions.
5 changes: 2 additions & 3 deletions src/block/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ use crate::sink::Sink;
use crate::sink::SliceSink;
#[allow(unused_imports)]
use alloc::vec;
use alloc::vec::Vec;

#[cfg(feature = "safe-encode")]
use core::convert::TryInto;
#[allow(unused_imports)]
use alloc::vec::Vec;

use super::hashtable::HashTable4K;
use super::hashtable::HashTable4KU16;
Expand Down
1 change: 1 addition & 0 deletions src/block/decompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::block::{DecompressError, MINMATCH};
use crate::fastcpy_unsafe;
use crate::sink::SliceSink;
use crate::sink::{PtrSink, Sink};
#[allow(unused_imports)]
use alloc::vec::Vec;

/// Copies data to output_ptr by self-referential copy from start and match_length
Expand Down
5 changes: 3 additions & 2 deletions src/block/decompress_safe.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//! The block decompression algorithm.
use core::convert::TryInto;

use crate::block::DecompressError;
use crate::block::MINMATCH;
use crate::sink::Sink;
use crate::sink::SliceSink;

#[allow(unused_imports)]
use alloc::vec;
#[allow(unused_imports)]
use alloc::vec::Vec;

/// Read an integer.
Expand Down
3 changes: 2 additions & 1 deletion src/block/hashtable.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[allow(unused_imports)]
use alloc::boxed::Box;
use core::convert::TryInto;

/// The Hashtable trait used by the compression to store hashed bytes to their position.
/// `val` can be maximum the size of the input in bytes.
Expand Down Expand Up @@ -36,6 +36,7 @@ fn hash5(sequence: usize) -> u32 {
pub trait HashTable {
fn get_at(&self, pos: usize) -> usize;
fn put_at(&mut self, pos: usize, val: usize);
#[allow(dead_code)]
fn clear(&mut self);
#[inline]
#[cfg(target_pointer_width = "64")]
Expand Down
1 change: 0 additions & 1 deletion src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub(crate) mod decompress;
pub use compress::*;
pub use decompress::*;

use core::convert::TryInto;
use core::fmt;

pub(crate) const WINDOW_SIZE: usize = 64 * 1024;
Expand Down
1 change: 0 additions & 1 deletion src/fastcpy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ fn double_copy_trick<const SIZE: usize>(src: &[u8], dst: &mut [u8]) {
#[cfg(test)]
mod tests {
use super::slice_copy;
use alloc::vec::Vec;
use proptest::prelude::*;
proptest! {
#[test]
Expand Down
1 change: 0 additions & 1 deletion src/fastcpy_unsafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ fn double_copy_trick<const SIZE: usize>(src: *const u8, dst: *mut u8, len: usize
#[cfg(test)]
mod tests {
use super::slice_copy;
use alloc::vec::Vec;
use proptest::prelude::*;
proptest! {
#[test]
Expand Down
5 changes: 2 additions & 3 deletions src/frame/decompress.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
convert::TryInto,
fmt,
hash::Hasher,
io::{self, BufRead, ErrorKind},
Expand Down Expand Up @@ -371,7 +370,7 @@ impl<R: io::Read> io::Read for FrameDecoder<R> {
let mut written = 0;
loop {
match self.fill_buf() {
Ok(b) if b.is_empty() => return Ok(written),
Ok([]) => return Ok(written),
Ok(b) => {
let s = std::str::from_utf8(b).map_err(|_| {
io::Error::new(
Expand All @@ -394,7 +393,7 @@ impl<R: io::Read> io::Read for FrameDecoder<R> {
let mut written = 0;
loop {
match self.fill_buf() {
Ok(b) if b.is_empty() => return Ok(written),
Ok([]) => return Ok(written),
Ok(b) => {
buf.extend_from_slice(b);
let len = b.len();
Expand Down
1 change: 0 additions & 1 deletion src/frame/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use twox_hash::XxHash32;

use super::Error;
use std::{
convert::TryInto,
fmt::Debug,
hash::Hasher,
io,
Expand Down
9 changes: 5 additions & 4 deletions src/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ pub fn vec_sink_for_compression(
pos: usize,
required_capacity: usize,
) -> SliceSink {
return {
{
vec.resize(offset + required_capacity, 0);
SliceSink::new(&mut vec[offset..], pos)
};
}
}

/// Returns a Sink implementation appropriate for outputing up to `required_capacity`
Expand All @@ -35,10 +35,10 @@ pub fn vec_sink_for_decompression(
pos: usize,
required_capacity: usize,
) -> SliceSink {
return {
{
vec.resize(offset + required_capacity, 0);
SliceSink::new(&mut vec[offset..], pos)
};
}
}

pub trait Sink {
Expand All @@ -47,6 +47,7 @@ pub trait Sink {
unsafe fn pos_mut_ptr(&mut self) -> *mut u8;

/// read byte at position
#[allow(dead_code)]
fn byte_at(&mut self, pos: usize) -> u8;

/// Pushes a byte to the end of the Sink.
Expand Down
5 changes: 5 additions & 0 deletions src/test_bins/compress_block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
use lz4_flex::compress_prepend_size;
let input = "Hello people, what's up?".to_string();
let _compressed = compress_prepend_size(input.as_bytes());
}
2 changes: 1 addition & 1 deletion tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[macro_use]
extern crate more_asserts;

use std::{convert::TryInto, iter};
use std::iter;

use lz4_compress::compress as lz4_rust_compress;
#[cfg(feature = "frame")]
Expand Down

0 comments on commit 566d29f

Please sign in to comment.