@@ -647,21 +647,17 @@ unsafe fn ZDICT_trainBuffer_legacy(
647647 } else {
648648 // build reverse suffix sort
649649 let mut reverseSuffix = vec ! [ 0u32 ; bufferSize] ;
650- let mut pos: size_t = 0 ;
651- pos = 0 ;
652- while pos < bufferSize {
650+ for pos in 0 ..bufferSize {
653651 reverseSuffix[ suffix[ pos] as usize ] = pos as u32 ;
654- pos = pos. wrapping_add ( 1 ) ;
655652 }
653+
656654 // Note: filePos tracks borders between samples.
657655 // It's not used at this stage, but planned to become useful in a later update
658656 * filePos = 0 ;
659- pos = 1 ;
660- while pos < nbFiles as size_t {
657+ for pos in 1 ..nbFiles as size_t {
661658 * filePos. add ( pos) = ( * filePos. add ( pos. wrapping_sub ( 1 ) ) as size_t )
662659 . wrapping_add ( * fileSizes. add ( pos. wrapping_sub ( 1 ) ) )
663660 as u32 ;
664- pos = pos. wrapping_add ( 1 ) ;
665661 }
666662
667663 if notificationLevel >= 2 {
@@ -671,38 +667,36 @@ unsafe fn ZDICT_trainBuffer_legacy(
671667 eprintln ! ( "minimum ratio : {} " , minRatio) ;
672668 }
673669
674- let mut cursor: u32 = 0 ;
675- cursor = 0 ;
676- while ( cursor as size_t ) < bufferSize {
677- let mut solution = DictItem :: default ( ) ;
678- if * doneMarks. offset ( cursor as isize ) != 0 {
679- cursor = cursor. wrapping_add ( 1 ) ;
680- } else {
681- solution = ZDICT_analyzePos (
682- doneMarks,
683- & suffix,
684- reverseSuffix[ cursor as usize ] ,
685- buffer,
686- minRatio,
687- notificationLevel,
670+ let mut cursor = 0usize ;
671+ while cursor < bufferSize {
672+ if * doneMarks. add ( cursor) != 0 {
673+ cursor += 1 ;
674+ continue ;
675+ }
676+
677+ let solution = ZDICT_analyzePos (
678+ doneMarks,
679+ & suffix,
680+ reverseSuffix[ cursor] ,
681+ buffer,
682+ minRatio,
683+ notificationLevel,
684+ ) ;
685+ if solution. length == 0 {
686+ cursor += 1 ;
687+ continue ;
688+ }
689+
690+ ZDICT_insertDictItem ( dictList, dictListSize, solution, buffer) ;
691+ cursor += solution. length as usize ;
692+
693+ if notificationLevel >= 2 && displayClock. elapsed ( ) > refresh_rate {
694+ displayClock = Instant :: now ( ) ;
695+ eprint ! (
696+ "\r {:4.2} % \r " ,
697+ cursor as core:: ffi:: c_double / bufferSize as core:: ffi:: c_double
698+ * 100.0f64 ,
688699 ) ;
689- if solution. length == 0 {
690- cursor = cursor. wrapping_add ( 1 ) ;
691- } else {
692- ZDICT_insertDictItem ( dictList, dictListSize, solution, buffer) ;
693- cursor = cursor. wrapping_add ( solution. length ) ;
694- if notificationLevel >= 2 {
695- if displayClock. elapsed ( ) > refresh_rate {
696- displayClock = Instant :: now ( ) ;
697- eprint ! (
698- "\r {:4.2} % \r " ,
699- cursor as core:: ffi:: c_double
700- / bufferSize as core:: ffi:: c_double
701- * 100.0f64 ,
702- ) ;
703- }
704- }
705- }
706700 }
707701 }
708702 }
0 commit comments