Divisions-by-two for a positive Py_ssize_t compile more cleanly with >>1 than /2.

This commit is contained in:
Raymond Hettinger 2015-07-20 00:25:50 -04:00
parent 498b5e98e9
commit cfe5b6ca04
2 changed files with 4 additions and 4 deletions

View File

@ -788,7 +788,7 @@ deque_reverse(dequeobject *deque, PyObject *unused)
block *rightblock = deque->rightblock; block *rightblock = deque->rightblock;
Py_ssize_t leftindex = deque->leftindex; Py_ssize_t leftindex = deque->leftindex;
Py_ssize_t rightindex = deque->rightindex; Py_ssize_t rightindex = deque->rightindex;
Py_ssize_t n = Py_SIZE(deque) / 2; Py_ssize_t n = Py_SIZE(deque) >> 1;
Py_ssize_t i; Py_ssize_t i;
PyObject *tmp; PyObject *tmp;

View File

@ -66,7 +66,7 @@ siftup(PyListObject *heap, Py_ssize_t pos)
/* Bubble up the smaller child until hitting a leaf. */ /* Bubble up the smaller child until hitting a leaf. */
arr = _PyList_ITEMS(heap); 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) { while (pos < limit) {
/* Set childpos to index of smaller child. */ /* Set childpos to index of smaller child. */
childpos = 2*pos + 1; /* leftmost child position */ 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, 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. 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)) if (siftup_func((PyListObject *)heap, i))
return NULL; return NULL;
Py_RETURN_NONE; Py_RETURN_NONE;
@ -420,7 +420,7 @@ siftup_max(PyListObject *heap, Py_ssize_t pos)
/* Bubble up the smaller child until hitting a leaf. */ /* Bubble up the smaller child until hitting a leaf. */
arr = _PyList_ITEMS(heap); 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) { while (pos < limit) {
/* Set childpos to index of smaller child. */ /* Set childpos to index of smaller child. */
childpos = 2*pos + 1; /* leftmost child position */ childpos = 2*pos + 1; /* leftmost child position */