Update of /cvsroot/jython/jython/org/python/core
In directory usw-pr-cvs1:/tmp/cvs-serv25342
Modified Files:
PyList.java
Log Message:
docompare(): Compare using the rich-comp interface.
Index: PyList.java
===================================================================
RCS file: /cvsroot/jython/jython/org/python/core/PyList.java,v
retrieving revision 2.18
retrieving revision 2.19
diff -C2 -r2.18 -r2.19
*** PyList.java 2001/02/02 09:28:37 2.18
--- PyList.java 2001/02/21 14:34:09 2.19
***************
*** 409,415 ****
* function is NULL.
*/
! private static int docompare(PyObject x, PyObject y, PyObject compare) {
! if (compare == null)
! return x._cmp(y);
PyObject ret = compare.__call__(new PyObject[] {x, y});
--- 409,425 ----
* function is NULL.
*/
! private static int docompare(PyObject x, PyObject y,
! PyObject compare, String cmpop) {
! if (compare == null) {
! /* NOTE: we rely on the fact here that the sorting algorithm
! only ever checks whether k<0, i.e., whether x<y. So we
! invoke the rich comparison function with _lt ('<'), and
! return -1 when it returns true and 0 when it returns
! false. */
! if (cmpop == "<")
! return x._lt(y).__nonzero__() ? -1 : 0;
! if (cmpop == "<=")
! return x._le(y).__nonzero__() ? -1 : 1;
! }
PyObject ret = compare.__call__(new PyObject[] {x, y});
***************
*** 432,436 ****
while (--j >= off) {
PyObject q = array[j];
! if (docompare(q, key, compare) <= 0)
break;
array[j+1] = q;
--- 442,446 ----
while (--j >= off) {
PyObject q = array[j];
! if (docompare(q, key, compare, "<=") <= 0)
break;
array[j+1] = q;
***************
*** 495,509 ****
left = array[l]; right = array[lo];
! if (docompare(left, right, compare) < 0) {
array[lo] = left; array[l] = right;
}
left = array[r]; right = array[l];
! if (docompare(left, right, compare) < 0) {
array[r] = left; array[l] = right;
}
left = array[l]; right = array[lo];
! if (docompare(left, right, compare) < 0) {
array[lo] = left; array[l] = right;
}
--- 505,519 ----
left = array[l]; right = array[lo];
! if (docompare(left, right, compare, "<") < 0) {
array[lo] = left; array[l] = right;
}
left = array[r]; right = array[l];
! if (docompare(left, right, compare, "<") < 0) {
array[r] = left; array[l] = right;
}
left = array[l]; right = array[lo];
! if (docompare(left, right, compare, "<") < 0) {
array[lo] = left; array[l] = right;
}
***************
*** 516,520 ****
/* Move left index to element > pivot */
while (l < hi) {
! if (docompare(array[l], pivot, compare) >= 0)
break;
l++;
--- 526,530 ----
/* Move left index to element > pivot */
while (l < hi) {
! if (docompare(array[l], pivot, compare, "<") >= 0)
break;
l++;
***************
*** 522,526 ****
/* Move right index to element < pivot */
while (r >= lo) {
! if (docompare(pivot, array[r], compare) >= 0)
break;
r--;
--- 532,536 ----
/* Move right index to element < pivot */
while (r >= lo) {
! if (docompare(pivot, array[r], compare, "<") >= 0)
break;
r--;
|