@@ -31,8 +31,8 @@ public static IEnumerable<T[]> SubsetsProgressive<T>(this IReadOnlyList<T> sourc
3131 }
3232
3333 var lastSlot = count - 1 ;
34- var pool = ArrayPool < int > . Shared ;
35- var indices = pool . Rent ( lastSlot ) ;
34+ var pool = lastSlot > 128 ? ArrayPool < int > . Shared : null ;
35+ var indices = pool ? . Rent ( lastSlot ) ?? new int [ lastSlot ] ;
3636 try
3737 {
3838 using var e = source . GetEnumerator ( ) ;
@@ -53,7 +53,7 @@ public static IEnumerable<T[]> SubsetsProgressive<T>(this IReadOnlyList<T> sourc
5353 buffer [ lastSlot ] = e . Current ;
5454 foreach ( var _ in Collections . Subsets . IndexesInternal ( n , lastSlot , indices ) )
5555 {
56- for ( var i = 0 ; i < lastSlot ; i ++ )
56+ for ( var i = 0 ; i < lastSlot ; i ++ )
5757 buffer [ i ] = source [ indices [ i ] ] ;
5858
5959 yield return buffer ;
@@ -63,7 +63,7 @@ public static IEnumerable<T[]> SubsetsProgressive<T>(this IReadOnlyList<T> sourc
6363 }
6464 finally
6565 {
66- pool . Return ( indices ) ;
66+ pool ? . Return ( indices ) ;
6767 }
6868 }
6969
@@ -72,8 +72,8 @@ public static IEnumerable<T[]> SubsetsProgressive<T>(this IReadOnlyList<T> sourc
7272 /// <returns>An enumerable containing the resultant subsets as a memory buffer.</returns>
7373 public static IEnumerable < ReadOnlyMemory < T > > SubsetsProgressiveBuffered < T > ( this IReadOnlyList < T > source , int count )
7474 {
75- var pool = ArrayPool < T > . Shared ;
76- var buffer = pool . Rent ( count ) ;
75+ var pool = count > 128 ? ArrayPool < T > . Shared : null ;
76+ var buffer = pool ? . Rent ( count ) ?? new T [ count ] ;
7777 var readBuffer = new ReadOnlyMemory < T > ( buffer , 0 , count ) ;
7878 try
7979 {
@@ -82,7 +82,7 @@ public static IEnumerable<ReadOnlyMemory<T>> SubsetsProgressiveBuffered<T>(this
8282 }
8383 finally
8484 {
85- pool . Return ( buffer , true ) ;
85+ pool ? . Return ( buffer , true ) ;
8686 }
8787 }
8888
0 commit comments