@@ -25,8 +25,8 @@ public static class FastLinq
2525 /// <param name="action">The action to execute on each element.</param>
2626 public static void ForEachFast < T > ( this ReadOnlySpan < T > span , Action < T > action )
2727 {
28- for ( int i = 0 ; i < span . Length ; i ++ )
29- action ( span [ i ] ) ;
28+ foreach ( var t in span )
29+ action ( t ) ;
3030 }
3131
3232 /// <summary>
@@ -38,8 +38,8 @@ public static void ForEachFast<T>(this ReadOnlySpan<T> span, Action<T> action)
3838 /// <param name="action">The action to execute on each element.</param>
3939 public static void ForEachFast < T > ( this Span < T > span , Action < T > action )
4040 {
41- for ( int i = 0 ; i < span . Length ; i ++ )
42- action ( span [ i ] ) ;
41+ foreach ( var t in span )
42+ action ( t ) ;
4343 }
4444
4545 /// <summary>
@@ -78,9 +78,10 @@ public static int WhereFast<T>(
7878 Func < T , bool > predicate )
7979 {
8080 int count = 0 ;
81- for ( int i = 0 ; i < span . Length ; i ++ )
82- if ( predicate ( span [ i ] ) )
83- destination [ count ++ ] = span [ i ] ;
81+ foreach ( var t in span )
82+ if ( predicate ( t ) )
83+ destination [ count ++ ] = t ;
84+
8485 return count ;
8586 }
8687
@@ -99,8 +100,9 @@ public static TResult AggregateFast<T, TResult>(
99100 Func < TResult , T , TResult > func )
100101 {
101102 var acc = seed ;
102- for ( int i = 0 ; i < span . Length ; i ++ )
103- acc = func ( acc , span [ i ] ) ;
103+ foreach ( var t in span )
104+ acc = func ( acc , t ) ;
105+
104106 return acc ;
105107 }
106108
@@ -126,9 +128,10 @@ public static bool AnyFast<T>(this ReadOnlySpan<T> span)
126128 /// <returns>True if all elements satisfy the predicate; otherwise false.</returns>
127129 public static bool AllFast < T > ( this ReadOnlySpan < T > span , Func < T , bool > predicate )
128130 {
129- for ( int i = 0 ; i < span . Length ; i ++ )
130- if ( ! predicate ( span [ i ] ) )
131+ foreach ( var t in span )
132+ if ( ! predicate ( t ) )
131133 return false ;
134+
132135 return true ;
133136 }
134137
0 commit comments