From acffb377a8331c1a8a5d7cc14a19f460a3323ee2 Mon Sep 17 00:00:00 2001 From: olehougaard Date: Fri, 26 Sep 2008 09:15:02 +0000 Subject: [PATCH] Fix for issue 95. Fixed QuickSort so it doesn't overflow the stack with non-reflexsive comparison functions. Review URL: http://codereview.chromium.org/4297 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@382 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/array.js | 7 ++++++- test/mozilla/mozilla.status | 2 -- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/array.js b/src/array.js index 396e5e8..3d32c18 100644 --- a/src/array.js +++ b/src/array.js @@ -672,8 +672,10 @@ function ArraySort(comparefn) { if (from >= to - 1) return; var pivot_index = $floor($random() * (to - from)) + from; var pivot = a[pivot_index]; + a[pivot_index] = a[to - 1]; + a[to - 1] = pivot; var low_end = from; // Upper bound of the elements lower than pivot. - var high_start = to; // Lower bound of the elements greater than pivot. + var high_start = to - 1; // Lower bound of the elements greater than pivot. for (var i = from; i < high_start; ) { var element = a[i]; var order = Compare(element, pivot); @@ -690,6 +692,9 @@ function ArraySort(comparefn) { i++; } } + a[to - 1] = a[high_start]; + a[high_start] = pivot; + high_start++; QuickSort(a, from, low_end); QuickSort(a, high_start, to); } diff --git a/test/mozilla/mozilla.status b/test/mozilla/mozilla.status index 681b5f0..b43ea17 100644 --- a/test/mozilla/mozilla.status +++ b/test/mozilla/mozilla.status @@ -45,8 +45,6 @@ prefix mozilla def FAIL_OK = FAIL, OKAY -js1_5/Array/regress-360681-01: FAIL - ##################### SKIPPED TESTS ##################### # This test checks that we behave properly in an out-of-memory -- 2.7.4