From dd9c085ae359506d7cedb31d7036aa4604f8b08c Mon Sep 17 00:00:00 2001 From: Randall Luecke Date: Wed, 11 Aug 2010 22:33:14 -0500 Subject: [PATCH] Fix for new sort being unstable with a huge thanks to Shon Frazier. Reviewed by Me and Alexander Ljungberg. --- Foundation/CPArray.j | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Foundation/CPArray.j b/Foundation/CPArray.j index cb19f0edb..14931c0bc 100755 --- a/Foundation/CPArray.j +++ b/Foundation/CPArray.j @@ -1326,7 +1326,7 @@ CPEnumerationReverse = 1 << 1; */ - (void)sortUsingFunction:(Function)aFunction context:(id)aContext { - var h, i, j, k, l, m, n = [self count]; + var h, i, j, k, l, m, n = [self count], o; var A, B = []; for (h = 1; h < n; h += h) @@ -1343,7 +1343,8 @@ CPEnumerationReverse = 1 << 1; for (i = 0, k = l; k < j && j <= m + h; k++) { A = self[j]; - if (aFunction(A, B[i], aContext) == CPOrderedDescending) + o = aFunction(A, B[i], aContext); + if (o == CPOrderedDescending || o == CPOrderedSame) self[k] = B[i++]; else {