summaryrefslogtreecommitdiffstats
path: root/Modules/_heapqmodule.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2015-12-08 04:45:16 (GMT)
committerRaymond Hettinger <python@rcn.com>2015-12-08 04:45:16 (GMT)
commit2300bf29e69ec9ecee563134f8cdfdab93b2a7c0 (patch)
treed3957f32e3f7f8d2ebf6de9b69b15f7476beaed6 /Modules/_heapqmodule.c
parente7ceef66ddf7a0ee4341087992d262fc5edf5cfb (diff)
downloadcpython-2300bf29e69ec9ecee563134f8cdfdab93b2a7c0.zip
cpython-2300bf29e69ec9ecee563134f8cdfdab93b2a7c0.tar.gz
cpython-2300bf29e69ec9ecee563134f8cdfdab93b2a7c0.tar.bz2
Only update the arr variable when PyObject_RichCompareBool() has been called.
Diffstat (limited to 'Modules/_heapqmodule.c')
-rw-r--r--Modules/_heapqmodule.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c
index 28604af..1c37c75 100644
--- a/Modules/_heapqmodule.c
+++ b/Modules/_heapqmodule.c
@@ -78,6 +78,7 @@ siftup(PyListObject *heap, Py_ssize_t pos)
if (cmp < 0)
return -1;
childpos += ((unsigned)cmp ^ 1); /* increment when cmp==0 */
+ arr = _PyList_ITEMS(heap); /* arr may have changed */
if (endpos != PyList_GET_SIZE(heap)) {
PyErr_SetString(PyExc_RuntimeError,
"list changed size during iteration");
@@ -85,7 +86,6 @@ siftup(PyListObject *heap, Py_ssize_t pos)
}
}
/* Move the smaller child up. */
- arr = _PyList_ITEMS(heap);
tmp1 = arr[childpos];
tmp2 = arr[pos];
arr[childpos] = tmp2;
@@ -432,6 +432,7 @@ siftup_max(PyListObject *heap, Py_ssize_t pos)
if (cmp < 0)
return -1;
childpos += ((unsigned)cmp ^ 1); /* increment when cmp==0 */
+ arr = _PyList_ITEMS(heap); /* arr may have changed */
if (endpos != PyList_GET_SIZE(heap)) {
PyErr_SetString(PyExc_RuntimeError,
"list changed size during iteration");
@@ -439,7 +440,6 @@ siftup_max(PyListObject *heap, Py_ssize_t pos)
}
}
/* Move the smaller child up. */
- arr = _PyList_ITEMS(heap);
tmp1 = arr[childpos];
tmp2 = arr[pos];
arr[childpos] = tmp2;