@@ -723,7 +723,7 @@ where
723723 }
724724 }
725725
726- fn apply_core_contiguous < F , Acc > ( & mut self , mut acc : Acc , mut function : F ) -> FoldWhile < Acc >
726+ fn apply_core_contiguous < F , Acc > ( & mut self , acc : Acc , mut function : F ) -> FoldWhile < Acc >
727727 where
728728 F : FnMut ( Acc , P :: Item ) -> FoldWhile < Acc > ,
729729 P : ZippableTuple < Dim = D > ,
@@ -732,15 +732,35 @@ where
732732 let size = self . dimension . size ( ) ;
733733 let ptrs = self . parts . as_ptr ( ) ;
734734 let inner_strides = self . parts . contiguous_stride ( ) ;
735- for i in 0 ..size {
736- unsafe {
737- let ptr_i = ptrs. stride_offset ( inner_strides, i) ;
738- acc = fold_while ! [ function( acc, self . parts. as_ref( ptr_i) ) ] ;
739- }
735+ unsafe {
736+ self . inner ( acc, ptrs, inner_strides, size, & mut function)
737+ }
738+ }
739+
740+ /// The innermost loop of the Zip apply methods
741+ ///
742+ /// Run the fold while operation on a stretch of elements with constant strides
743+ ///
744+ /// `ptr`: base pointer for the first element in this stretch
745+ /// `strides`: strides for the elements in this stretch
746+ /// `len`: number of elements
747+ /// `function`: closure
748+ unsafe fn inner < F , Acc > ( & self , mut acc : Acc , ptr : P :: Ptr , strides : P :: Stride ,
749+ len : usize , function : & mut F ) -> FoldWhile < Acc >
750+ where
751+ F : FnMut ( Acc , P :: Item ) -> FoldWhile < Acc > ,
752+ P : ZippableTuple
753+ {
754+ let mut i = 0 ;
755+ while i < len {
756+ let p = ptr. stride_offset ( strides, i) ;
757+ acc = fold_while ! ( function( acc, self . parts. as_ref( p) ) ) ;
758+ i += 1 ;
740759 }
741760 FoldWhile :: Continue ( acc)
742761 }
743762
763+
744764 fn apply_core_strided < F , Acc > ( & mut self , acc : Acc , function : F ) -> FoldWhile < Acc >
745765 where
746766 F : FnMut ( Acc , P :: Item ) -> FoldWhile < Acc > ,
@@ -773,15 +793,11 @@ where
773793 while let Some ( index) = index_ {
774794 unsafe {
775795 let ptr = self . parts . uget_ptr ( & index) ;
776- for i in 0 ..inner_len {
777- let p = ptr. stride_offset ( inner_strides, i) ;
778- acc = fold_while ! ( function( acc, self . parts. as_ref( p) ) ) ;
779- }
796+ acc = fold_while ! [ self . inner( acc, ptr, inner_strides, inner_len, & mut function) ] ;
780797 }
781798
782799 index_ = self . dimension . next_for ( index) ;
783800 }
784- self . dimension [ unroll_axis] = inner_len;
785801 FoldWhile :: Continue ( acc)
786802 }
787803
@@ -801,18 +817,14 @@ where
801817 loop {
802818 unsafe {
803819 let ptr = self . parts . uget_ptr ( & index) ;
804- for i in 0 ..inner_len {
805- let p = ptr. stride_offset ( inner_strides, i) ;
806- acc = fold_while ! ( function( acc, self . parts. as_ref( p) ) ) ;
807- }
820+ acc = fold_while ! [ self . inner( acc, ptr, inner_strides, inner_len, & mut function) ] ;
808821 }
809822
810823 if !self . dimension . next_for_f ( & mut index) {
811824 break ;
812825 }
813826 }
814827 }
815- self . dimension [ unroll_axis] = inner_len;
816828 FoldWhile :: Continue ( acc)
817829 }
818830
0 commit comments