Kaydet (Commit) 2300bf29 authored tarafından Raymond Hettinger's avatar Raymond Hettinger

Only update the arr variable when PyObject_RichCompareBool() has been called.

üst e7ceef66
...@@ -78,6 +78,7 @@ siftup(PyListObject *heap, Py_ssize_t pos) ...@@ -78,6 +78,7 @@ siftup(PyListObject *heap, Py_ssize_t pos)
if (cmp < 0) if (cmp < 0)
return -1; return -1;
childpos += ((unsigned)cmp ^ 1); /* increment when cmp==0 */ childpos += ((unsigned)cmp ^ 1); /* increment when cmp==0 */
arr = _PyList_ITEMS(heap); /* arr may have changed */
if (endpos != PyList_GET_SIZE(heap)) { if (endpos != PyList_GET_SIZE(heap)) {
PyErr_SetString(PyExc_RuntimeError, PyErr_SetString(PyExc_RuntimeError,
"list changed size during iteration"); "list changed size during iteration");
...@@ -85,7 +86,6 @@ siftup(PyListObject *heap, Py_ssize_t pos) ...@@ -85,7 +86,6 @@ siftup(PyListObject *heap, Py_ssize_t pos)
} }
} }
/* Move the smaller child up. */ /* Move the smaller child up. */
arr = _PyList_ITEMS(heap);
tmp1 = arr[childpos]; tmp1 = arr[childpos];
tmp2 = arr[pos]; tmp2 = arr[pos];
arr[childpos] = tmp2; arr[childpos] = tmp2;
...@@ -432,6 +432,7 @@ siftup_max(PyListObject *heap, Py_ssize_t pos) ...@@ -432,6 +432,7 @@ siftup_max(PyListObject *heap, Py_ssize_t pos)
if (cmp < 0) if (cmp < 0)
return -1; return -1;
childpos += ((unsigned)cmp ^ 1); /* increment when cmp==0 */ childpos += ((unsigned)cmp ^ 1); /* increment when cmp==0 */
arr = _PyList_ITEMS(heap); /* arr may have changed */
if (endpos != PyList_GET_SIZE(heap)) { if (endpos != PyList_GET_SIZE(heap)) {
PyErr_SetString(PyExc_RuntimeError, PyErr_SetString(PyExc_RuntimeError,
"list changed size during iteration"); "list changed size during iteration");
...@@ -439,7 +440,6 @@ siftup_max(PyListObject *heap, Py_ssize_t pos) ...@@ -439,7 +440,6 @@ siftup_max(PyListObject *heap, Py_ssize_t pos)
} }
} }
/* Move the smaller child up. */ /* Move the smaller child up. */
arr = _PyList_ITEMS(heap);
tmp1 = arr[childpos]; tmp1 = arr[childpos];
tmp2 = arr[pos]; tmp2 = arr[pos];
arr[childpos] = tmp2; arr[childpos] = tmp2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment