@@ -4,7 +4,8 @@ const MAX_L1_DISTANCE: u16 = 8192;
44/// Returns the length of the data after compression through FastLZ, based on
55// https://github.com/Vectorized/solady/blob/5315d937d79b335c668896d7533ac603adac5315/js/solady.js
66pub ( crate ) fn flz_compress_len ( input : & [ u8 ] ) -> u32 {
7- let mut idx: u32 = 0 ;
7+ let mut idx: u32 = 2 ;
8+
89 let idx_limit: u32 = if input. len ( ) < 13 {
910 0
1011 } else {
@@ -13,8 +14,6 @@ pub(crate) fn flz_compress_len(input: &[u8]) -> u32 {
1314
1415 let mut anchor = 0 ;
1516
16- idx += 2 ;
17-
1817 let mut size = 0 ;
1918
2019 let mut htab = [ 0 ; 8192 ] ;
@@ -33,7 +32,7 @@ pub(crate) fn flz_compress_len(input: &[u8]) -> u32 {
3332 break ;
3433 }
3534 idx += 1 ;
36- if distance <= MAX_L1_DISTANCE as u32 && seq == u24 ( input, r) {
35+ if distance < MAX_L1_DISTANCE as u32 && seq == u24 ( input, r) {
3736 break ;
3837 }
3938 }
@@ -130,7 +129,7 @@ fn solady_flz_compress(ib: &[u8]) -> u32 {
130129
131130 fn hash ( x : u32 ) -> u32 {
132131 ( ( ( 2654435769 * x as u64 ) >> 19 ) & 8191 ) as u32
133- } ;
132+ }
134133
135134 fn literals ( mut r : u32 , mut s : u32 , ib : & [ u8 ] , ob : & mut Vec < u8 > ) {
136135 while r >= 32 {
@@ -151,7 +150,7 @@ fn solady_flz_compress(ib: &[u8]) -> u32 {
151150 r -= 1 ;
152151 }
153152 } ;
154- } ;
153+ }
155154
156155 while i < b - 9 {
157156 loop {
@@ -248,10 +247,15 @@ mod tests {
248247
249248 #[ test]
250249 fn test_flz_solady_parity ( ) {
251- for _ in 0 ..1000 {
252- let mut input = [ 0 ; 4096 ] ;
250+ for _ in 0 ..100 {
251+ let mut input = [ 0 ; 1000000 ] ;
253252 rand:: thread_rng ( ) . fill_bytes ( & mut input) ;
254- assert_eq ! ( flz_compress_len( & input) , solady_flz_compress( & input) ) ;
253+ assert_eq ! (
254+ flz_compress_len( & input) ,
255+ solady_flz_compress( & input) ,
256+ "{:?}" ,
257+ input
258+ ) ;
255259 }
256260 }
257261}
0 commit comments