[Python-checkins] cpython: Since the index is always non-negative, use faster unsigned division and modulo.
raymond.hettinger
python-checkins at python.org
Fri Feb 27 21:43:00 CET 2015
https://hg.python.org/cpython/rev/91a1613e161c
changeset: 94780:91a1613e161c
user: Raymond Hettinger <python at rcn.com>
date: Fri Feb 27 12:42:54 2015 -0800
summary:
Since the index is always non-negative, use faster unsigned division and modulo.
files:
Modules/_collectionsmodule.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -142,7 +142,7 @@
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 @@
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 @@
(hash = ((PyASCIIObject *) key)->hash) == -1)
{
hash = PyObject_Hash(key);
- if (hash == -1)
+ if (hash == -1)
goto done;
}
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list