@@ -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 defined by <see cref="RowInterval"/>-s .
22+ /// Iterate through the rows of a rectangle in optimized batches.
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 <see cref="RowInterval"/> .</param>
27+ /// <param name="body">The method body defining the iteration logic on a single row .</param>
2828 [ MethodImpl ( InliningOptions . ShortMethod ) ]
2929 public static void IterateRows < T > ( Rectangle rectangle , Configuration configuration , in T body )
30- where T : struct , IRowIntervalAction
30+ where T : struct , IRowAction
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 defined by <see cref="RowInterval"/>-s .
37+ /// Iterate through the rows of a rectangle in optimized batches.
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 <see cref="RowInterval"/> .</param>
42+ /// <param name="body">The method body defining the iteration logic on a single row .</param>
4343 public static void IterateRows < T > (
4444 Rectangle rectangle ,
4545 in ParallelExecutionSettings parallelSettings ,
4646 in T body )
47- where T : struct , IRowIntervalAction
47+ where T : struct , IRowAction
4848 {
4949 ValidateRectangle ( rectangle ) ;
5050
@@ -59,15 +59,17 @@ public static void IterateRows<T>(
5959 // Avoid TPL overhead in this trivial case:
6060 if ( numOfSteps == 1 )
6161 {
62- var rows = new RowInterval ( top , bottom ) ;
63- Unsafe . AsRef ( body ) . Invoke ( in rows ) ;
62+ for ( int y = top ; y < bottom ; y ++ )
63+ {
64+ Unsafe . AsRef ( body ) . Invoke ( y ) ;
65+ }
66+
6467 return ;
6568 }
6669
6770 int verticalStep = DivideCeil ( rectangle . Height , numOfSteps ) ;
6871 var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps } ;
69- var rowInfo = new WrappingRowIntervalInfo ( top , bottom , verticalStep ) ;
70- var rowAction = new WrappingRowIntervalAction < T > ( in rowInfo , in body ) ;
72+ var rowAction = new WrappingRowAction < T > ( top , bottom , verticalStep , in body ) ;
7173
7274 Parallel . For (
7375 0 ,
@@ -86,7 +88,7 @@ public static void IterateRows<T>(
8688 /// <param name="configuration">The <see cref="Configuration"/> to get the parallel settings from.</param>
8789 /// <param name="body">The method body defining the iteration logic on a single <see cref="RowInterval"/>.</param>
8890 public static void IterateRows < T , TBuffer > ( Rectangle rectangle , Configuration configuration , in T body )
89- where T : struct , IRowIntervalAction < TBuffer >
91+ where T : struct , IRowAction < TBuffer >
9092 where TBuffer : unmanaged
9193 {
9294 var parallelSettings = ParallelExecutionSettings . FromConfiguration ( configuration ) ;
@@ -101,7 +103,7 @@ internal static void IterateRows<T, TBuffer>(
101103 Rectangle rectangle ,
102104 in ParallelExecutionSettings parallelSettings ,
103105 in T body )
104- where T : struct , IRowIntervalAction < TBuffer >
106+ where T : struct , IRowAction < TBuffer >
105107 where TBuffer : unmanaged
106108 {
107109 ValidateRectangle ( rectangle ) ;
@@ -118,19 +120,22 @@ internal static void IterateRows<T, TBuffer>(
118120 // Avoid TPL overhead in this trivial case:
119121 if ( numOfSteps == 1 )
120122 {
121- var rows = new RowInterval ( top , bottom ) ;
122123 using ( IMemoryOwner < TBuffer > buffer = allocator . Allocate < TBuffer > ( width ) )
123124 {
124- Unsafe . AsRef ( body ) . Invoke ( rows , buffer . Memory ) ;
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+ }
125131 }
126132
127133 return ;
128134 }
129135
130136 int verticalStep = DivideCeil ( height , numOfSteps ) ;
131137 var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = numOfSteps } ;
132- var rowInfo = new WrappingRowIntervalInfo ( top , bottom , verticalStep , width ) ;
133- var rowAction = new WrappingRowIntervalBufferAction < T , TBuffer > ( in rowInfo , allocator , in body ) ;
138+ var rowAction = new WrappingRowAction < T , TBuffer > ( top , bottom , verticalStep , width , allocator , in body ) ;
134139
135140 Parallel . For (
136141 0 ,
0 commit comments