mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Added separate free list for cfunction (builtin method) objects, for a
few percent speed up. Also add PyCFunction_Fini() to discard it.
This commit is contained in:
parent
404b95d9ba
commit
1f39c5c666
1 changed files with 30 additions and 7 deletions
|
@ -38,21 +38,31 @@ PERFORMANCE OF THIS SOFTWARE.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
PyMethodDef *m_ml;
|
PyMethodDef *m_ml;
|
||||||
PyObject *m_self;
|
PyObject *m_self;
|
||||||
} PyCFunctionObject;
|
} PyCFunctionObject;
|
||||||
|
|
||||||
|
static PyCFunctionObject *free_list = NULL;
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
PyCFunction_New(ml, self)
|
PyCFunction_New(ml, self)
|
||||||
PyMethodDef *ml;
|
PyMethodDef *ml;
|
||||||
PyObject *self;
|
PyObject *self;
|
||||||
{
|
{
|
||||||
PyCFunctionObject *op = PyObject_NEW(PyCFunctionObject,
|
PyCFunctionObject *op;
|
||||||
&PyCFunction_Type);
|
op = free_list;
|
||||||
if (op != NULL) {
|
if (op != NULL) {
|
||||||
op->m_ml = ml;
|
free_list = (PyCFunctionObject *)(op->m_self);
|
||||||
Py_XINCREF(self);
|
op->ob_type = &PyCFunction_Type;
|
||||||
op->m_self = self;
|
_Py_NewReference(op);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
op = PyObject_NEW(PyCFunctionObject, &PyCFunction_Type);
|
||||||
|
if (op == NULL)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
op->m_ml = ml;
|
||||||
|
Py_XINCREF(self);
|
||||||
|
op->m_self = self;
|
||||||
return (PyObject *)op;
|
return (PyObject *)op;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +106,8 @@ meth_dealloc(m)
|
||||||
PyCFunctionObject *m;
|
PyCFunctionObject *m;
|
||||||
{
|
{
|
||||||
Py_XDECREF(m->m_self);
|
Py_XDECREF(m->m_self);
|
||||||
free((char *)m);
|
m->m_self = (PyObject *)free_list;
|
||||||
|
free_list = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -267,3 +278,15 @@ Py_FindMethod(methods, self, name)
|
||||||
chain.link = NULL;
|
chain.link = NULL;
|
||||||
return Py_FindMethodInChain(&chain, self, name);
|
return Py_FindMethodInChain(&chain, self, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Clear out the free list */
|
||||||
|
|
||||||
|
void
|
||||||
|
PyCFunction_Fini()
|
||||||
|
{
|
||||||
|
while (free_list) {
|
||||||
|
PyCFunctionObject *v = free_list;
|
||||||
|
free_list = (PyCFunctionObject *)(v->m_self);
|
||||||
|
PyMem_DEL(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue