[Python-checkins] cpython (merge 3.4 -> default): merge
raymond.hettinger
python-checkins at python.org
Sun May 4 00:26:33 CEST 2014
http://hg.python.org/cpython/rev/5d076506b3f5
changeset: 90543:5d076506b3f5
parent: 90541:62438d1b11c7
parent: 90542:725cb631699a
user: Raymond Hettinger <python at rcn.com>
date: Sat May 03 15:26:17 2014 -0700
summary:
merge
files:
Modules/_heapqmodule.c | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c
--- a/Modules/_heapqmodule.c
+++ b/Modules/_heapqmodule.c
@@ -62,7 +62,7 @@
static int
_siftup(PyListObject *heap, Py_ssize_t pos)
{
- Py_ssize_t startpos, endpos, childpos, rightpos;
+ Py_ssize_t startpos, endpos, childpos, rightpos, limit;
int cmp;
PyObject *newitem, *tmp, *olditem;
Py_ssize_t size;
@@ -79,9 +79,10 @@
Py_INCREF(newitem);
/* Bubble up the smaller child until hitting a leaf. */
- childpos = 2*pos + 1; /* leftmost child position */
- while (childpos < endpos) {
+ limit = endpos / 2; /* smallest pos that has no child */
+ while (pos < limit) {
/* Set childpos to index of smaller child. */
+ childpos = 2*pos + 1; /* leftmost child position */
rightpos = childpos + 1;
if (rightpos < endpos) {
cmp = PyObject_RichCompareBool(
@@ -108,7 +109,6 @@
PyList_SET_ITEM(heap, pos, tmp);
Py_DECREF(olditem);
pos = childpos;
- childpos = 2*pos + 1;
if (size != PyList_GET_SIZE(heap)) {
PyErr_SetString(PyExc_RuntimeError,
"list changed size during iteration");
@@ -419,7 +419,7 @@
static int
_siftupmax(PyListObject *heap, Py_ssize_t pos)
{
- Py_ssize_t startpos, endpos, childpos, rightpos;
+ Py_ssize_t startpos, endpos, childpos, rightpos, limit;
int cmp;
PyObject *newitem, *tmp;
@@ -434,9 +434,10 @@
Py_INCREF(newitem);
/* Bubble up the smaller child until hitting a leaf. */
- childpos = 2*pos + 1; /* leftmost child position */
- while (childpos < endpos) {
+ limit = endpos / 2; /* smallest pos that has no child */
+ while (pos < limit) {
/* Set childpos to index of smaller child. */
+ childpos = 2*pos + 1; /* leftmost child position */
rightpos = childpos + 1;
if (rightpos < endpos) {
cmp = PyObject_RichCompareBool(
@@ -456,7 +457,6 @@
Py_DECREF(PyList_GET_ITEM(heap, pos));
PyList_SET_ITEM(heap, pos, tmp);
pos = childpos;
- childpos = 2*pos + 1;
}
/* The leaf at pos is empty now. Put newitem there, and bubble
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list