summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2015-02-27 20:42:54 (GMT)
committerRaymond Hettinger <python@rcn.com>2015-02-27 20:42:54 (GMT)
commitda2850f93269b8daf0b1c3d6d1303162a98c13f6 (patch)
tree124452a5a54ef3397210fbb246bb49db490b4bbb /Modules
parentb44ed82b81944f405d7e3e9974e7baf2456a9eee (diff)
downloadcpython-da2850f93269b8daf0b1c3d6d1303162a98c13f6.zip
cpython-da2850f93269b8daf0b1c3d6d1303162a98c13f6.tar.gz
cpython-da2850f93269b8daf0b1c3d6d1303162a98c13f6.tar.bz2
Since the index is always non-negative, use faster unsigned division and modulo.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_collectionsmodule.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 0df35d9..0bc0e98 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -142,7 +142,7 @@ typedef struct {
static PyTypeObject deque_type;
-/* XXX Todo:
+/* XXX Todo:
If aligned memory allocations become available, make the
deque object 64 byte aligned so that all of the fields
can be retrieved or updated in a single cache line.
@@ -780,7 +780,9 @@ deque_item(dequeobject *deque, Py_ssize_t i)
b = deque->rightblock;
} else {
i += deque->leftindex;
- n = i / BLOCKLEN;
+ assert(i >= 0);
+ n = (Py_ssize_t)((unsigned) i / BLOCKLEN);
+ i = (Py_ssize_t)((unsigned) i % BLOCKLEN);
i %= BLOCKLEN;
if (index < (Py_SIZE(deque) >> 1)) {
b = deque->leftblock;
@@ -1848,7 +1850,7 @@ _count_elements(PyObject *self, PyObject *args)
(hash = ((PyASCIIObject *) key)->hash) == -1)
{
hash = PyObject_Hash(key);
- if (hash == -1)
+ if (hash == -1)
goto done;
}