diff options
author | Raymond Hettinger <python@rcn.com> | 2015-07-20 04:25:50 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2015-07-20 04:25:50 (GMT) |
commit | cfe5b6ca04a14ef1ba42e78bf6da05cfa9c0b66b (patch) | |
tree | 6b54b92e45cbb3a21c1679a7bcabc38413203991 /Modules/_heapqmodule.c | |
parent | 498b5e98e9aaf5057d73cda1940b9c2d93305455 (diff) | |
download | cpython-cfe5b6ca04a14ef1ba42e78bf6da05cfa9c0b66b.zip cpython-cfe5b6ca04a14ef1ba42e78bf6da05cfa9c0b66b.tar.gz cpython-cfe5b6ca04a14ef1ba42e78bf6da05cfa9c0b66b.tar.bz2 |
Divisions-by-two for a positive Py_ssize_t compile more cleanly with >>1 than /2.
Diffstat (limited to 'Modules/_heapqmodule.c')
-rw-r--r-- | Modules/_heapqmodule.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c index c343862..28604af 100644 --- a/Modules/_heapqmodule.c +++ b/Modules/_heapqmodule.c @@ -66,7 +66,7 @@ siftup(PyListObject *heap, Py_ssize_t pos) /* Bubble up the smaller child until hitting a leaf. */ arr = _PyList_ITEMS(heap); - limit = endpos / 2; /* smallest pos that has no child */ + limit = endpos >> 1; /* smallest pos that has no child */ while (pos < limit) { /* Set childpos to index of smaller child. */ childpos = 2*pos + 1; /* leftmost child position */ @@ -347,7 +347,7 @@ heapify_internal(PyObject *heap, int siftup_func(PyListObject *, Py_ssize_t)) n is odd = 2*j+1, this is (2*j+1-1)/2 = j so j-1 is the largest, and that's again n//2-1. */ - for (i = n/2 - 1 ; i >= 0 ; i--) + for (i = (n >> 1) - 1 ; i >= 0 ; i--) if (siftup_func((PyListObject *)heap, i)) return NULL; Py_RETURN_NONE; @@ -420,7 +420,7 @@ siftup_max(PyListObject *heap, Py_ssize_t pos) /* Bubble up the smaller child until hitting a leaf. */ arr = _PyList_ITEMS(heap); - limit = endpos / 2; /* smallest pos that has no child */ + limit = endpos >> 1; /* smallest pos that has no child */ while (pos < limit) { /* Set childpos to index of smaller child. */ childpos = 2*pos + 1; /* leftmost child position */ |