@@ -617,20 +617,31 @@ trait CDFContextLogOps: CDFContextLogSize {
617617 #[ inline( always) ]
618618 fn rollback (
619619 log : & mut CDFContextLogBase , fc : & mut CDFContext , checkpoint : usize ,
620+ map : & FieldMap ,
620621 ) {
621622 let base = fc as * mut _ as * mut u8 ;
622623 let mut len = log. data . len ( ) ;
624+ let mut summary = std:: collections:: HashMap :: new ( ) ;
625+ let mut rollback_count = 0 ;
623626 unsafe {
624627 let mut src = log. data . get_unchecked_mut ( len) as * mut u16 ;
625628 while len > checkpoint {
626629 len -= Self :: CDF_LEN_MAX + 1 ;
627630 src = src. sub ( Self :: CDF_LEN_MAX + 1 ) ;
628631 let offset = * src. add ( Self :: CDF_LEN_MAX ) as usize ;
629632 let dst = base. add ( offset) as * mut u16 ;
633+ if let Some ( name) = map. lookup ( dst as usize ) {
634+ summary. entry ( name) . and_modify ( |v| * v += 1 ) . or_insert ( 1 ) ;
635+ }
630636 dst. copy_from_nonoverlapping ( src, Self :: CDF_LEN_MAX ) ;
637+ rollback_count += 1 ;
631638 }
632639 log. data . set_len ( len) ;
633640 }
641+ print ! ( " {}" , rollback_count) ;
642+ /* for (name, count) in summary.iter() {
643+ println!(" {}: {}", name, count);
644+ } */
634645 }
635646}
636647
@@ -685,9 +696,13 @@ impl CDFContextLog {
685696 #[ inline( always) ]
686697 pub fn rollback (
687698 & mut self , fc : & mut CDFContext , checkpoint : & CDFContextCheckpoint ,
699+ map : & FieldMap ,
688700 ) {
689- CDFContextLogSmall :: rollback ( & mut self . small . 0 , fc, checkpoint. small ) ;
690- CDFContextLogLarge :: rollback ( & mut self . large . 0 , fc, checkpoint. large ) ;
701+ print ! ( "{:p}, " , checkpoint) ;
702+ CDFContextLogSmall :: rollback ( & mut self . small . 0 , fc, checkpoint. small , map) ;
703+ print ! ( ", " ) ;
704+ CDFContextLogLarge :: rollback ( & mut self . large . 0 , fc, checkpoint. large , map) ;
705+ println ! ( "" ) ;
691706 }
692707 pub fn clear ( & mut self ) {
693708 self . small . 0 . data . clear ( ) ;
@@ -699,7 +714,6 @@ pub struct ContextWriter<'a> {
699714 pub bc : BlockContext < ' a > ,
700715 pub fc : & ' a mut CDFContext ,
701716 pub fc_log : CDFContextLog ,
702- #[ cfg( feature = "desync_finder" ) ]
703717 pub fc_map : Option < FieldMap > , // For debugging purposes
704718}
705719
@@ -708,18 +722,9 @@ impl<'a> ContextWriter<'a> {
708722 pub fn new ( fc : & ' a mut CDFContext , bc : BlockContext < ' a > ) -> Self {
709723 let fc_log = CDFContextLog :: new ( fc) ;
710724 #[ allow( unused_mut) ]
711- let mut cw = ContextWriter {
712- fc,
713- bc,
714- fc_log,
715- #[ cfg( feature = "desync_finder" ) ]
716- fc_map : Default :: default ( ) ,
717- } ;
718- #[ cfg( feature = "desync_finder" ) ]
725+ let mut cw = ContextWriter { fc, bc, fc_log, fc_map : Default :: default ( ) } ;
719726 {
720- if std:: env:: var_os ( "RAV1E_DEBUG" ) . is_some ( ) {
721- cw. fc_map = Some ( FieldMap { map : cw. fc . build_map ( ) } ) ;
722- }
727+ cw. fc_map = Some ( FieldMap { map : cw. fc . build_map ( ) } ) ;
723728 }
724729
725730 cw
@@ -740,13 +745,11 @@ impl<'a> ContextWriter<'a> {
740745 }
741746
742747 pub fn rollback ( & mut self , checkpoint : & ContextWriterCheckpoint ) {
743- self . fc_log . rollback ( & mut self . fc , & checkpoint. fc ) ;
748+ self . fc_log . rollback (
749+ & mut self . fc ,
750+ & checkpoint. fc ,
751+ self . fc_map . as_ref ( ) . unwrap ( ) ,
752+ ) ;
744753 self . bc . rollback ( & checkpoint. bc ) ;
745- #[ cfg( feature = "desync_finder" ) ]
746- {
747- if self . fc_map . is_some ( ) {
748- self . fc_map = Some ( FieldMap { map : self . fc . build_map ( ) } ) ;
749- }
750- }
751754 }
752755}
0 commit comments