Adding comment to the fix of issue 95.
authorolehougaard <olehougaard@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 26 Sep 2008 10:25:14 +0000 (10:25 +0000)
committerolehougaard <olehougaard@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 26 Sep 2008 10:25:14 +0000 (10:25 +0000)
Review URL: http://codereview.chromium.org/5003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@383 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/array.js

index 3d32c18..0f75cb6 100644 (file)
@@ -672,6 +672,8 @@ function ArraySort(comparefn) {
     if (from >= to - 1) return;
     var pivot_index = $floor($random() * (to - from)) + from;
     var pivot = a[pivot_index];
+    // Issue 95: Keep the pivot element out of the comparisons to avoid
+    // infinite recursion if comparefn(pivot, pivot) != 0.
     a[pivot_index] = a[to - 1];
     a[to - 1] = pivot;
     var low_end = from;   // Upper bound of the elements lower than pivot.
@@ -692,6 +694,7 @@ function ArraySort(comparefn) {
         i++;
       }
     }
+    // Restore the pivot element to its rightful place.
     a[to - 1] = a[high_start];
     a[high_start] = pivot;
     high_start++;