summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2013-06-25 18:34:48 (GMT)
committerBenjamin Peterson <benjamin@python.org>2013-06-25 18:34:48 (GMT)
commit227f0faed2138cebd43cf1973d8bb72ad70fca5a (patch)
tree1125dfc710eeed23c909f181753afdbc4116f756
parent3968e299593f6cec7a79fab41fa43f32da61b9a9 (diff)
downloadcpython-227f0faed2138cebd43cf1973d8bb72ad70fca5a.zip
cpython-227f0faed2138cebd43cf1973d8bb72ad70fca5a.tar.gz
cpython-227f0faed2138cebd43cf1973d8bb72ad70fca5a.tar.bz2
reapply 5accb0ac8bfb
-rw-r--r--Lib/test/test_deque.py2
-rw-r--r--Modules/_collectionsmodule.c18
2 files changed, 8 insertions, 12 deletions
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py
index 595a0c4..98b203e 100644
--- a/Lib/test/test_deque.py
+++ b/Lib/test/test_deque.py
@@ -522,7 +522,7 @@ class TestBasic(unittest.TestCase):
@test_support.cpython_only
def test_sizeof(self):
- BLOCKLEN = 62
+ BLOCKLEN = 64
basesize = test_support.calcobjsize('2P4PlP')
blocksize = struct.calcsize('2P%dP' % BLOCKLEN)
self.assertEqual(object.__sizeof__(deque()), basesize)
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 371631c..8a43d9a 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -8,12 +8,13 @@
*/
/* The block length may be set to any number over 1. Larger numbers
- * reduce the number of calls to the memory allocator but take more
- * memory. Ideally, BLOCKLEN should be set with an eye to the
- * length of a cache line.
+ * reduce the number of calls to the memory allocator, give faster
+ * indexing and rotation, and reduce the link::data overhead ratio.
+ * Ideally, the block length should be a power-of-two for faster
+ * division/modulo computations during indexing.
*/
-#define BLOCKLEN 62
+#define BLOCKLEN 64
#define CENTER ((BLOCKLEN - 1) / 2)
/* A `dequeobject` is composed of a doubly-linked list of `block` nodes.
@@ -58,13 +59,8 @@ static block *freeblocks[MAXFREEBLOCKS];
static block *
newblock(block *leftlink, block *rightlink, Py_ssize_t len) {
block *b;
- /* To prevent len from overflowing PY_SSIZE_T_MAX on 64-bit machines, we
- * refuse to allocate new blocks if the current len is dangerously
- * close. There is some extra margin to prevent spurious arithmetic
- * overflows at various places. The following check ensures that
- * the blocks allocated to the deque, in the worst case, can only
- * have PY_SSIZE_T_MAX-2 entries in total.
- */
+ /* To prevent len from overflowing PY_SSIZE_T_MAX on 32-bit machines, we
+ * refuse to allocate new blocks if the current len is nearing overflow. */
if (len >= PY_SSIZE_T_MAX - 2*BLOCKLEN) {
PyErr_SetString(PyExc_OverflowError,
"cannot add more blocks to the deque");