]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix comment blocks. Adjust blocksize to a power-of-two for better divmod computations.
authorRaymond Hettinger <python@rcn.com>
Fri, 14 Jun 2013 05:06:33 +0000 (01:06 -0400)
committerRaymond Hettinger <python@rcn.com>
Fri, 14 Jun 2013 05:06:33 +0000 (01:06 -0400)
Lib/test/test_deque.py
Modules/_collectionsmodule.c

index 595a0c4a35cace415f66468eb046664d63c2ec63..98b203edb60a730f33ea4e2e405ae0137553d2ba 100644 (file)
@@ -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)
index 371631ce2661d98cae8ad8421dd770d650999551..8a43d9a028a2b9f29436d33100584da77ebe8464 100644 (file)
@@ -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");