mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
bpo-37340: remove free_list for bound method objects (GH-14232)
This commit is contained in:
parent
76b645124b
commit
3e54b57531
5 changed files with 14 additions and 101 deletions
|
@ -7,15 +7,6 @@
|
|||
#include "pycore_pystate.h"
|
||||
#include "structmember.h"
|
||||
|
||||
/* Free list for method objects to safe malloc/free overhead
|
||||
* The m_self element is used to chain the objects.
|
||||
*/
|
||||
static PyCFunctionObject *free_list = NULL;
|
||||
static int numfree = 0;
|
||||
#ifndef PyCFunction_MAXFREELIST
|
||||
#define PyCFunction_MAXFREELIST 256
|
||||
#endif
|
||||
|
||||
/* undefine macro trampoline to PyCFunction_NewEx */
|
||||
#undef PyCFunction_New
|
||||
|
||||
|
@ -66,17 +57,10 @@ PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
PyCFunctionObject *op;
|
||||
op = free_list;
|
||||
if (op != NULL) {
|
||||
free_list = (PyCFunctionObject *)(op->m_self);
|
||||
(void)PyObject_INIT(op, &PyCFunction_Type);
|
||||
numfree--;
|
||||
}
|
||||
else {
|
||||
op = PyObject_GC_New(PyCFunctionObject, &PyCFunction_Type);
|
||||
if (op == NULL)
|
||||
return NULL;
|
||||
PyCFunctionObject *op =
|
||||
PyObject_GC_New(PyCFunctionObject, &PyCFunction_Type);
|
||||
if (op == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
op->m_weakreflist = NULL;
|
||||
op->m_ml = ml;
|
||||
|
@ -130,14 +114,7 @@ meth_dealloc(PyCFunctionObject *m)
|
|||
}
|
||||
Py_XDECREF(m->m_self);
|
||||
Py_XDECREF(m->m_module);
|
||||
if (numfree < PyCFunction_MAXFREELIST) {
|
||||
m->m_self = (PyObject *)free_list;
|
||||
free_list = m;
|
||||
numfree++;
|
||||
}
|
||||
else {
|
||||
PyObject_GC_Del(m);
|
||||
}
|
||||
PyObject_GC_Del(m);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -338,16 +315,7 @@ PyTypeObject PyCFunction_Type = {
|
|||
int
|
||||
PyCFunction_ClearFreeList(void)
|
||||
{
|
||||
int freelist_size = numfree;
|
||||
|
||||
while (free_list) {
|
||||
PyCFunctionObject *v = free_list;
|
||||
free_list = (PyCFunctionObject *)(v->m_self);
|
||||
PyObject_GC_Del(v);
|
||||
numfree--;
|
||||
}
|
||||
assert(numfree == 0);
|
||||
return freelist_size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -356,15 +324,6 @@ PyCFunction_Fini(void)
|
|||
(void)PyCFunction_ClearFreeList();
|
||||
}
|
||||
|
||||
/* Print summary info about the state of the optimized allocator */
|
||||
void
|
||||
_PyCFunction_DebugMallocStats(FILE *out)
|
||||
{
|
||||
_PyDebugAllocatorStats(out,
|
||||
"free PyCFunctionObject",
|
||||
numfree, sizeof(PyCFunctionObject));
|
||||
}
|
||||
|
||||
|
||||
/* Vectorcall functions for each of the PyCFunction calling conventions,
|
||||
* except for METH_VARARGS (possibly combined with METH_KEYWORDS) which
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue