diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2020-06-23 13:50:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-23 13:50:15 (GMT) |
commit | 32f2eda85957365d208f499b730d30b7eb419741 (patch) | |
tree | e30a2c8595534b46c7e402889d8d87816868353b | |
parent | 1d3dad5f96ed445b958ec53dfa0d46812f2162d9 (diff) | |
download | cpython-32f2eda85957365d208f499b730d30b7eb419741.zip cpython-32f2eda85957365d208f499b730d30b7eb419741.tar.gz cpython-32f2eda85957365d208f499b730d30b7eb419741.tar.bz2 |
bpo-40521: Remove freelist from collections.deque() (GH-21073)
-rw-r--r-- | Misc/NEWS.d/next/Library/2020-06-23-06-09-59.bpo-40521.HUfxP7.rst | 1 | ||||
-rw-r--r-- | Modules/_collectionsmodule.c | 23 |
2 files changed, 3 insertions, 21 deletions
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 index 0000000..7689a14 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-23-06-09-59.bpo-40521.HUfxP7.rst @@ -0,0 +1 @@ +Remove freelist from collections.deque(). diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 7120e4d..00198ff 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -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 * |