Explorar o código

Use Array.Sort instead of QuickSort.

Bart De Smet %!s(int64=6) %!d(string=hai) anos
pai
achega
f311d17495

+ 9 - 0
Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/OrderBy.cs

@@ -42,6 +42,15 @@ namespace Tests
             Assert.Throws<ArgumentNullException>(() => AsyncEnumerable.ThenByDescending(xs, default, Comparer<int>.Default));
         }
 
+        [Fact]
+        public async Task OrderBy_Empty()
+        {
+            var ys = AsyncEnumerable.Empty<int>().OrderBy(x => x);
+
+            var e = ys.GetAsyncEnumerator();
+            await NoNextAsync(e);
+        }
+
         [Fact]
         public async Task OrderBy1()
         {

+ 1 - 60
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/OrderedAsyncEnumerable.cs

@@ -625,66 +625,7 @@ namespace System.Linq
 
         private int CompareKeys(int index1, int index2) => index1 == index2 ? 0 : CompareAnyKeys(index1, index2);
 
-        protected override void QuickSort(int[] map, int left, int right)
-        {
-            // REVIEW: Consider using Array.Sort, see https://github.com/dotnet/corefx/commit/a6aff797a33e606a60ec0c9ca034a161c609620f#diff-d90239bd8284188e2bd210790483f5ca.
-
-            do
-            {
-                var i = left;
-                var j = right;
-                var x = map[i + ((j - i) >> 1)];
-
-                do
-                {
-                    while (i < map.Length && CompareKeys(x, map[i]) > 0)
-                    {
-                        i++;
-                    }
-
-                    while (j >= 0 && CompareKeys(x, map[j]) < 0)
-                    {
-                        j--;
-                    }
-
-                    if (i > j)
-                    {
-                        break;
-                    }
-
-                    if (i < j)
-                    {
-                        var temp = map[i];
-                        map[i] = map[j];
-                        map[j] = temp;
-                    }
-
-                    i++;
-                    j--;
-                }
-                while (i <= j);
-
-                if (j - left <= right - i)
-                {
-                    if (left < j)
-                    {
-                        QuickSort(map, left, j);
-                    }
-
-                    left = i;
-                }
-                else
-                {
-                    if (i < right)
-                    {
-                        QuickSort(map, i, right);
-                    }
-
-                    right = j;
-                }
-            }
-            while (left < right);
-        }
+        protected override void QuickSort(int[] keys, int lo, int hi) => Array.Sort(keys, lo, hi - lo + 1, Comparer<int>.Create(CompareAnyKeys));
 
         protected override void PartialQuickSort(int[] map, int left, int right, int minIndexInclusive, int maxIndexInclusive)
         {