Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 32f2eda

Browse files
authored
bpo-40521: Remove freelist from collections.deque() (GH-21073)
1 parent 1d3dad5 commit 32f2eda

File tree

2 files changed

+3
-21
lines changed

2 files changed

+3
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove freelist from collections.deque().

Modules/_collectionsmodule.c

+2-21
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,9 @@ static PyTypeObject deque_type;
117117
#define CHECK_NOT_END(link)
118118
#endif
119119

120-
/* A simple freelisting scheme is used to minimize calls to the memory
121-
allocator. It accommodates common use cases where new blocks are being
122-
added at about the same rate as old blocks are being freed.
123-
*/
124-
125-
#define MAXFREEBLOCKS 16
126-
static Py_ssize_t numfreeblocks = 0;
127-
static block *freeblocks[MAXFREEBLOCKS];
128-
129120
static block *
130121
newblock(void) {
131-
block *b;
132-
if (numfreeblocks) {
133-
numfreeblocks--;
134-
return freeblocks[numfreeblocks];
135-
}
136-
b = PyMem_Malloc(sizeof(block));
122+
block *b = PyMem_Malloc(sizeof(block));
137123
if (b != NULL) {
138124
return b;
139125
}
@@ -144,12 +130,7 @@ newblock(void) {
144130
static void
145131
freeblock(block *b)
146132
{
147-
if (numfreeblocks < MAXFREEBLOCKS) {
148-
freeblocks[numfreeblocks] = b;
149-
numfreeblocks++;
150-
} else {
151-
PyMem_Free(b);
152-
}
133+
PyMem_Free(b);
153134
}
154135

155136
static PyObject *

0 commit comments

Comments
 (0)