Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove freelist from collections.deque().
23 changes: 2 additions & 21 deletions Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 *
Expand Down