Commit 227f0fae authored by Benjamin Peterson's avatar Benjamin Peterson

reapply 5accb0ac8bfb

parent 3968e299
...@@ -522,7 +522,7 @@ class TestBasic(unittest.TestCase): ...@@ -522,7 +522,7 @@ class TestBasic(unittest.TestCase):
@test_support.cpython_only @test_support.cpython_only
def test_sizeof(self): def test_sizeof(self):
BLOCKLEN = 62 BLOCKLEN = 64
basesize = test_support.calcobjsize('2P4PlP') basesize = test_support.calcobjsize('2P4PlP')
blocksize = struct.calcsize('2P%dP' % BLOCKLEN) blocksize = struct.calcsize('2P%dP' % BLOCKLEN)
self.assertEqual(object.__sizeof__(deque()), basesize) self.assertEqual(object.__sizeof__(deque()), basesize)
......
...@@ -8,12 +8,13 @@ ...@@ -8,12 +8,13 @@
*/ */
/* The block length may be set to any number over 1. Larger numbers /* 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 * reduce the number of calls to the memory allocator, give faster
* memory. Ideally, BLOCKLEN should be set with an eye to the * indexing and rotation, and reduce the link::data overhead ratio.
* length of a cache line. * 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) #define CENTER ((BLOCKLEN - 1) / 2)
/* A `dequeobject` is composed of a doubly-linked list of `block` nodes. /* A `dequeobject` is composed of a doubly-linked list of `block` nodes.
...@@ -58,13 +59,8 @@ static block *freeblocks[MAXFREEBLOCKS]; ...@@ -58,13 +59,8 @@ static block *freeblocks[MAXFREEBLOCKS];
static block * static block *
newblock(block *leftlink, block *rightlink, Py_ssize_t len) { newblock(block *leftlink, block *rightlink, Py_ssize_t len) {
block *b; block *b;
/* To prevent len from overflowing PY_SSIZE_T_MAX on 64-bit machines, we /* To prevent len from overflowing PY_SSIZE_T_MAX on 32-bit machines, we
* refuse to allocate new blocks if the current len is dangerously * refuse to allocate new blocks if the current len is nearing overflow. */
* 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.
*/
if (len >= PY_SSIZE_T_MAX - 2*BLOCKLEN) { if (len >= PY_SSIZE_T_MAX - 2*BLOCKLEN) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"cannot add more blocks to the deque"); "cannot add more blocks to the deque");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment