[System.Core] Remove generic indirection for ToArray
authorJérémie Laval <jeremie.laval@gmail.com>
Tue, 4 Sep 2012 11:12:57 +0000 (12:12 +0100)
committerJérémie Laval <jeremie.laval@gmail.com>
Tue, 4 Sep 2012 11:15:36 +0000 (12:15 +0100)
mcs/class/System.Core/System.Linq/ParallelEnumerable.cs

index 6236f485baaec0d86316a0b9eac93a486767202c..7f41668c468bfd296f0560a2415343a2ffc56520 100644 (file)
@@ -1963,32 +1963,50 @@ namespace System.Linq
                        if (source.Node.IsOrdered ())
                                return ToListOrdered (source).ToArray ();
 
-                       TSource[] result = null;
+                       var helper = new ArrayAggregateHelper<TSource> ();
+                       ParallelExecuter.ProcessAndAggregate<TSource, List<TSource>> (source.Node,
+                                                                                     helper.Seed,
+                                                                                     helper.Intermediate,
+                                                                                     helper.Final);
+
+                       return helper.Result;
+               }
 
-                       Func<List<TSource>, TSource, List<TSource>> intermediate = (list, e) => {
-                               list.Add (e); return list;
-                       };
+               class ArrayAggregateHelper<TSource>
+               {
+                       TSource[] result;
 
-                       Action<IList<List<TSource>>> final = (list) => {
+                       public TSource[] Result {
+                               get {
+                                       return result;
+                               }
+                       }
+
+                       internal List<TSource> Seed ()
+                       {
+                               return new List<TSource> ();
+                       }
+
+                       internal List<TSource> Intermediate (List<TSource> list, TSource e)
+                       {
+                               list.Add (e);
+                               return list;
+                       }
+
+                       internal void Final (IList<List<TSource>> list)
+                       {
                                int count = 0;
 
                                for (int i = 0; i < list.Count; i++)
-                                 count += list[i].Count;
+                                       count += list[i].Count;
 
                                result = new TSource[count];
                                int insertIndex = -1;
 
                                for (int i = 0; i < list.Count; i++)
-                                 for (int j = 0; j < list[i].Count; j++)
-                                   result [++insertIndex] = list[i][j];
-                       };
-
-                       ParallelExecuter.ProcessAndAggregate<TSource, List<TSource>> (source.Node,
-                                                                                     () => new List<TSource> (),
-                                                                                     intermediate,
-                                                                                     final);
-
-                       return result;
+                                       for (int j = 0; j < list[i].Count; j++)
+                                               result [++insertIndex] = list[i][j];
+                       }
                }
 
                public static Dictionary<TKey, TSource> ToDictionary<TSource, TKey> (this ParallelQuery<TSource> source,