Small logic fix in choosing step in Parallel.For
authorJérémie Laval <jeremie.laval@gmail.com>
Thu, 11 Nov 2010 14:06:31 +0000 (14:06 +0000)
committerJérémie Laval <jeremie.laval@gmail.com>
Thu, 11 Nov 2010 18:12:48 +0000 (18:12 +0000)
mcs/class/corlib/System.Threading.Tasks/Parallel.cs

index ea175f4ed733fe6900a86e175d0eb0e71938f1d5..c2eeccd0f5ad7886068eee581fd6c9fc3598dc05 100644 (file)
@@ -47,9 +47,10 @@ namespace System.Threading.Tasks
                        int num = Math.Min (GetBestWorkerNumber (),
                                            options != null && options.MaxDegreeOfParallelism != -1 ? options.MaxDegreeOfParallelism : int.MaxValue);
                        // Integer range that each task process
-                       step = Math.Min (5, (to - from) / num);
-                       if (step <= 0)
-                               step = 1;
+                       if ((step = (to - from) / num) < 5) {
+                               step = 5;
+                               num = (to - from) / 5;
+                       }
 
                        return num;
                }