mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
Revert "bpo-40521: Remove freelist from collections.deque() (GH-21073)" (GH-24944)
This reverts commit 32f2eda859.
It can be re-applied if the subinterpreter PEP is approved.
Otherwise, the commit degraded performance with no offsetting
benefit.
This commit is contained in:
parent
929c9039fe
commit
3bb19873ab
1 changed files with 21 additions and 2 deletions
|
|
@ -118,9 +118,23 @@ 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 = PyMem_Malloc(sizeof(block));
|
||||
block *b;
|
||||
if (numfreeblocks) {
|
||||
numfreeblocks--;
|
||||
return freeblocks[numfreeblocks];
|
||||
}
|
||||
b = PyMem_Malloc(sizeof(block));
|
||||
if (b != NULL) {
|
||||
return b;
|
||||
}
|
||||
|
|
@ -131,7 +145,12 @@ newblock(void) {
|
|||
static void
|
||||
freeblock(block *b)
|
||||
{
|
||||
PyMem_Free(b);
|
||||
if (numfreeblocks < MAXFREEBLOCKS) {
|
||||
freeblocks[numfreeblocks] = b;
|
||||
numfreeblocks++;
|
||||
} else {
|
||||
PyMem_Free(b);
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue