@@ -19,32 +19,32 @@ namespace SixLabors.ImageSharp.Advanced
1919 public static class ParallelRowIterator
2020 {
2121 /// <summary>
22- /// Iterate through the rows of a rectangle in optimized batches.
22+ /// Iterate through the rows of a rectangle in optimized batches defined by <see cref="RowInterval"/>-s .
2323 /// </summary>
2424 /// <typeparam name="T">The type of row action to perform.</typeparam>
2525 /// <param name="rectangle">The <see cref="Rectangle"/>.</param>
2626 /// <param name="configuration">The <see cref="Configuration"/> to get the parallel settings from.</param>
27- /// <param name="body">The method body defining the iteration logic on a single row .</param>
27+ /// <param name="body">The method body defining the iteration logic on a single <see cref="RowInterval"/> .</param>
2828 [ MethodImpl ( InliningOptions . ShortMethod ) ]
2929 public static void IterateRows < T > ( Rectangle rectangle , Configuration configuration , in T body )
30- where T : struct , IRowAction
30+ where T : struct , IRowIntervalAction
3131 {
3232 var parallelSettings = ParallelExecutionSettings . FromConfiguration ( configuration ) ;
3333 IterateRows ( rectangle , in parallelSettings , in body ) ;
3434 }
3535
3636 /// <summary>
37- /// Iterate through the rows of a rectangle in optimized batches.
37+ /// Iterate through the rows of a rectangle in optimized batches defined by <see cref="RowInterval"/>-s .
3838 /// </summary>
3939 /// <typeparam name="T">The type of row action to perform.</typeparam>
4040 /// <param name="rectangle">The <see cref="Rectangle"/>.</param>
4141 /// <param name="parallelSettings">The <see cref="ParallelExecutionSettings"/>.</param>
42- /// <param name="body">The method body defining the iteration logic on a single row .</param>
42+ /// <param name="body">The method body defining the iteration logic on a single <see cref="RowInterval"/> .</param>
4343 public static void IterateRows < T > (
4444 Rectangle rectangle ,
4545 in ParallelExecutionSettings parallelSettings ,
4646 in T body )
47- where T : struct , IRowAction
47+ where T : struct , IRowIntervalAction
4848 {
4949 ValidateRectangle ( rectangle ) ;
5050
@@ -59,17 +59,15 @@ public static void IterateRows<T>(
5959 // Avoid TPL overhead in this trivial case:
6060 if ( numOfSteps == 1 )
6161 {
62- for ( int y = top ; y < bottom ; y ++ )
63- {
64- Unsafe . AsRef ( body ) . Invoke ( y ) ;
65- }
66-
62+ var rows = new RowInterval ( top , bottom ) ;
63+ Unsafe . AsRef ( body ) . Invoke ( in rows ) ;
6764 return ;
6865 }
6966
7067 int verticalStep = DivideCeil ( rectangle . Height , numOfSteps ) ;
7168 var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps } ;
72- var rowAction = new WrappingRowAction < T > ( top , bottom , verticalStep , in body ) ;
69+ var rowInfo = new WrappingRowIntervalInfo ( top , bottom , verticalStep ) ;
70+ var rowAction = new WrappingRowIntervalAction < T > ( in rowInfo , in body ) ;
7371
7472 Parallel . For (
7573 0 ,
@@ -88,7 +86,7 @@ public static void IterateRows<T>(
8886 /// <param name="configuration">The <see cref="Configuration"/> to get the parallel settings from.</param>
8987 /// <param name="body">The method body defining the iteration logic on a single <see cref="RowInterval"/>.</param>
9088 public static void IterateRows < T , TBuffer > ( Rectangle rectangle , Configuration configuration , in T body )
91- where T : struct , IRowAction < TBuffer >
89+ where T : struct , IRowIntervalAction < TBuffer >
9290 where TBuffer : unmanaged
9391 {
9492 var parallelSettings = ParallelExecutionSettings . FromConfiguration ( configuration ) ;
@@ -103,7 +101,7 @@ internal static void IterateRows<T, TBuffer>(
103101 Rectangle rectangle ,
104102 in ParallelExecutionSettings parallelSettings ,
105103 in T body )
106- where T : struct , IRowAction < TBuffer >
104+ where T : struct , IRowIntervalAction < TBuffer >
107105 where TBuffer : unmanaged
108106 {
109107 ValidateRectangle ( rectangle ) ;
@@ -120,22 +118,19 @@ internal static void IterateRows<T, TBuffer>(
120118 // Avoid TPL overhead in this trivial case:
121119 if ( numOfSteps == 1 )
122120 {
121+ var rows = new RowInterval ( top , bottom ) ;
123122 using ( IMemoryOwner < TBuffer > buffer = allocator . Allocate < TBuffer > ( width ) )
124123 {
125- Span < TBuffer > span = buffer . Memory . Span ;
126-
127- for ( int y = top ; y < bottom ; y ++ )
128- {
129- Unsafe . AsRef ( body ) . Invoke ( y , span ) ;
130- }
124+ Unsafe . AsRef ( body ) . Invoke ( rows , buffer . Memory ) ;
131125 }
132126
133127 return ;
134128 }
135129
136130 int verticalStep = DivideCeil ( height , numOfSteps ) ;
137131 var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps } ;
138- var rowAction = new WrappingRowAction < T , TBuffer > ( top , bottom , verticalStep , width , allocator , in body ) ;
132+ var rowInfo = new WrappingRowIntervalInfo ( top , bottom , verticalStep , width ) ;
133+ var rowAction = new WrappingRowIntervalBufferAction < T , TBuffer > ( in rowInfo , allocator , in body ) ;
139134
140135 Parallel . For (
141136 0 ,
0 commit comments