Skip to content

Commit

Permalink
Reimplement #85
Browse files Browse the repository at this point in the history
  • Loading branch information
PSeitz committed May 6, 2023
1 parent a75f532 commit a8e28d1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 49 deletions.
44 changes: 0 additions & 44 deletions src/block/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,40 +179,6 @@ fn count_same_bytes(input: &[u8], cur: &mut usize, source: &[u8], candidate: usi
}
}

// compare 4 bytes block
#[cfg(target_pointer_width = "64")]
{
if input_end - *cur >= 4 {
let diff = read_u32_ptr(unsafe { input.as_ptr().add(*cur) }) ^ read_u32_ptr(source_ptr);

if diff == 0 {
*cur += 4;
unsafe {
source_ptr = source_ptr.add(4);
}
} else {
*cur += (diff.to_le().trailing_zeros() / 8) as usize;
return *cur - start;
}
}
}

// compare 2 bytes block
if input_end - *cur >= 2
&& unsafe { read_u16_ptr(input.as_ptr().add(*cur)) == read_u16_ptr(source_ptr) }
{
*cur += 2;
unsafe {
source_ptr = source_ptr.add(2);
}
}

if *cur < input_end
&& unsafe { input.as_ptr().add(*cur).read() } == unsafe { source_ptr.read() }
{
*cur += 1;
}

*cur - start
}

Expand Down Expand Up @@ -738,16 +704,6 @@ pub fn compress_prepend_size_with_dict(input: &[u8], ext_dict: &[u8]) -> Vec<u8>
compress_into_vec_with_dict::<true>(input, true, ext_dict)
}

#[inline]
#[cfg(not(feature = "safe-encode"))]
fn read_u16_ptr(input: *const u8) -> u16 {
let mut num: u16 = 0;
unsafe {
core::ptr::copy_nonoverlapping(input, &mut num as *mut u16 as *mut u8, 2);
}
num
}

#[inline]
#[cfg(not(feature = "safe-encode"))]
fn read_u32_ptr(input: *const u8) -> u32 {
Expand Down
9 changes: 4 additions & 5 deletions src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ pub(crate) const WINDOW_SIZE: usize = 64 * 1024;
///
/// When a block can reference data from another block, it can start immediately with a match and no
/// literal, so a block of 12 bytes can be compressed.
const MFLIMIT: usize = 12;
///
/// 8 bytes are added to the end, as a safety margin, so that the match bytes algorithm can always load
/// 8 bytes at once
const MFLIMIT: usize = 12 + 8;

/// The last 5 bytes of input are always literals. Therefore, the last sequence contains at least 5
/// bytes.
Expand Down Expand Up @@ -73,10 +76,6 @@ const MINMATCH: usize = 4;
#[allow(dead_code)]
const FASTLOOP_SAFE_DISTANCE: usize = 64;

/// Switch for the hashtable size byU16
#[allow(dead_code)]
static LZ4_64KLIMIT: usize = (64 * 1024) + (MFLIMIT - 1);

/// An error representing invalid compressed data.
#[derive(Debug)]
#[non_exhaustive]
Expand Down

0 comments on commit a8e28d1

Please sign in to comment.