@@ -2,10 +2,10 @@ use std::time::{Duration, Instant};
22
33use libc:: { free, malloc, memcpy, size_t} ;
44
5- use crate :: lib:: common:: bits:: { ZSTD_NbCommonBytes , ZSTD_highbit32 } ;
5+ use crate :: lib:: common:: bits:: ZSTD_highbit32 ;
66use crate :: lib:: common:: error_private:: { ERR_getErrorName , ERR_isError , Error } ;
77use crate :: lib:: common:: huf:: { HUF_CElt , HUF_CTABLE_WORKSPACE_SIZE_U32 , HUF_WORKSPACE_SIZE } ;
8- use crate :: lib:: common:: mem:: { MEM_readLE32 , MEM_readST , MEM_writeLE32 } ;
8+ use crate :: lib:: common:: mem:: { MEM_readLE32 , MEM_writeLE32 } ;
99use crate :: lib:: common:: xxhash:: ZSTD_XXH64 ;
1010use crate :: lib:: common:: zstd_internal:: {
1111 repStartValue, LLFSELog , MLFSELog , MaxLL , MaxML , OffFSELog , ZSTD_REP_NUM ,
@@ -128,26 +128,16 @@ pub unsafe extern "C" fn ZDICT_getDictHeaderSize(
128128 )
129129}
130130
131- unsafe fn ZDICT_count (
132- mut pIn : * const core:: ffi:: c_void ,
133- mut pMatch : * const core:: ffi:: c_void ,
134- ) -> size_t {
135- let pStart = pIn as * const core:: ffi:: c_char ;
136- loop {
137- let diff = MEM_readST ( pMatch) ^ MEM_readST ( pIn) ;
138- if diff == 0 {
139- pIn = pIn. byte_add ( :: core:: mem:: size_of :: < size_t > ( ) ) ;
140- pMatch = pMatch. byte_add ( :: core:: mem:: size_of :: < size_t > ( ) ) ;
141- } else {
142- pIn = pIn. byte_offset ( ZSTD_NbCommonBytes ( diff) as isize ) ;
143- return pIn. byte_offset_from ( pStart) as core:: ffi:: c_long as size_t ;
144- }
145- }
131+ fn ZDICT_count ( pIn : & [ u8 ] , pMatch : & [ u8 ] ) -> size_t {
132+ pIn. iter ( )
133+ . zip ( pMatch)
134+ . position ( |( a, b) | a != b)
135+ . unwrap_or ( 0 )
146136}
147137
148138const LLIMIT : usize = 64 ;
149139const MINMATCHLENGTH : usize = 7 ;
150- unsafe fn ZDICT_analyzePos (
140+ fn ZDICT_analyzePos (
151141 doneMarks : & mut [ bool ] ,
152142 suffix_slice : & [ u32 ] ,
153143 mut start : u32 ,
@@ -195,10 +185,7 @@ unsafe fn ZDICT_analyzePos(
195185 let mut length: size_t = 0 ;
196186 loop {
197187 end = end. wrapping_add ( 1 ) ;
198- length = ZDICT_count (
199- buffer[ pos..] . as_ptr ( ) as * const core:: ffi:: c_void ,
200- buffer[ suffix ( end as usize ) as usize ..] . as_ptr ( ) as * const core:: ffi:: c_void ,
201- ) ;
188+ length = ZDICT_count ( & buffer[ pos..] , & buffer[ suffix ( end as usize ) as usize ..] ) ;
202189 if length < MINMATCHLENGTH {
203190 break ;
204191 }
@@ -208,9 +195,8 @@ unsafe fn ZDICT_analyzePos(
208195 let mut length_0: size_t = 0 ;
209196 loop {
210197 length_0 = ZDICT_count (
211- buffer[ pos..] . as_ptr ( ) as * const core:: ffi:: c_void ,
212- buffer[ suffix ( ( start as usize ) . wrapping_sub ( 1 ) ) as usize ..] . as_ptr ( )
213- as * const core:: ffi:: c_void ,
198+ & buffer[ pos..] ,
199+ & buffer[ suffix ( ( start as usize ) . wrapping_sub ( 1 ) ) as usize ..] ,
214200 ) ;
215201 if length_0 >= MINMATCHLENGTH {
216202 start = start. wrapping_sub ( 1 ) ;
@@ -285,10 +271,7 @@ unsafe fn ZDICT_analyzePos(
285271 // look forward
286272 loop {
287273 end = end. wrapping_add ( 1 ) ;
288- let mut length = ZDICT_count (
289- buffer[ pos..] . as_ptr ( ) as * const core:: ffi:: c_void ,
290- buffer[ suffix ( end as usize ) as usize ..] . as_ptr ( ) as * const core:: ffi:: c_void ,
291- ) ;
274+ let mut length = ZDICT_count ( & buffer[ pos..] , & buffer[ suffix ( end as usize ) as usize ..] ) ;
292275 if length >= LLIMIT {
293276 length = LLIMIT - 1 ;
294277 }
@@ -302,9 +285,8 @@ unsafe fn ZDICT_analyzePos(
302285 let mut length_2 = MINMATCHLENGTH ;
303286 while ( length_2 >= MINMATCHLENGTH ) as core:: ffi:: c_int & ( start > 0 ) as core:: ffi:: c_int != 0 {
304287 length_2 = ZDICT_count (
305- buffer[ pos..] . as_ptr ( ) as * const core:: ffi:: c_void ,
306- buffer[ suffix ( start. wrapping_sub ( 1 ) as usize ) as usize ..] . as_ptr ( )
307- as * const core:: ffi:: c_void ,
288+ & buffer[ pos..] ,
289+ & buffer[ suffix ( start. wrapping_sub ( 1 ) as usize ) as usize ..] ,
308290 ) ;
309291 if length_2 >= LLIMIT {
310292 length_2 = LLIMIT - 1 ;
@@ -376,10 +358,7 @@ unsafe fn ZDICT_analyzePos(
376358 if testedPos as size_t == pos {
377359 length_3 = solution. length ;
378360 } else {
379- length_3 = ZDICT_count (
380- buffer[ pos..] . as_ptr ( ) as * const core:: ffi:: c_void ,
381- buffer[ testedPos as usize ..] . as_ptr ( ) as * const core:: ffi:: c_void ,
382- ) as u32 ;
361+ length_3 = ZDICT_count ( & buffer[ pos..] , & buffer[ testedPos as usize ..] ) as u32 ;
383362 if length_3 > solution. length {
384363 length_3 = solution. length ;
385364 }
0 commit comments