]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40521: Remove freelist from collections.deque() (GH-21073)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Tue, 23 Jun 2020 13:50:15 +0000 (06:50 -0700)
committerGitHub <noreply@github.com>
Tue, 23 Jun 2020 13:50:15 +0000 (06:50 -0700)
Misc/NEWS.d/next/Library/2020-06-23-06-09-59.bpo-40521.HUfxP7.rst [new file with mode: 0644]
Modules/_collectionsmodule.c

diff --git a/Misc/NEWS.d/next/Library/2020-06-23-06-09-59.bpo-40521.HUfxP7.rst b/Misc/NEWS.d/next/Library/2020-06-23-06-09-59.bpo-40521.HUfxP7.rst
new file mode 100644 (file)
index 0000000..7689a14
--- /dev/null
@@ -0,0 +1 @@
+Remove freelist from collections.deque().
index 7120e4dda0ed236cd99c420e4d483aa40b6b8d9a..00198ff3eb7ddbcecced6392e554a43dd13b2538 100644 (file)
@@ -117,23 +117,9 @@ static PyTypeObject deque_type;
 #define CHECK_NOT_END(link)
 #endif
 
-/* A simple freelisting scheme is used to minimize calls to the memory
-   allocator.  It accommodates common use cases where new blocks are being
-   added at about the same rate as old blocks are being freed.
- */
-
-#define MAXFREEBLOCKS 16
-static Py_ssize_t numfreeblocks = 0;
-static block *freeblocks[MAXFREEBLOCKS];
-
 static block *
 newblock(void) {
-    block *b;
-    if (numfreeblocks) {
-        numfreeblocks--;
-        return freeblocks[numfreeblocks];
-    }
-    b = PyMem_Malloc(sizeof(block));
+    block *b = PyMem_Malloc(sizeof(block));
     if (b != NULL) {
         return b;
     }
@@ -144,12 +130,7 @@ newblock(void) {
 static void
 freeblock(block *b)
 {
-    if (numfreeblocks < MAXFREEBLOCKS) {
-        freeblocks[numfreeblocks] = b;
-        numfreeblocks++;
-    } else {
-        PyMem_Free(b);
-    }
+    PyMem_Free(b);
 }
 
 static PyObject *