summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-08-05 02:11:41 (GMT)
committerGuido van Rossum <guido@python.org>1997-08-05 02:11:41 (GMT)
commit1f39c5c666ce8ede33b989aa816ed947affd1f7b (patch)
tree5754305ae2edd5736f147f89585afb50b2635226
parent404b95d9baaad27923381868b97bce3748f04d50 (diff)
downloadcpython-1f39c5c666ce8ede33b989aa816ed947affd1f7b.zip
cpython-1f39c5c666ce8ede33b989aa816ed947affd1f7b.tar.gz
cpython-1f39c5c666ce8ede33b989aa816ed947affd1f7b.tar.bz2
Added separate free list for cfunction (builtin method) objects, for a
few percent speed up. Also add PyCFunction_Fini() to discard it.
-rw-r--r--Objects/methodobject.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/Objects/methodobject.c b/Objects/methodobject.c
index c0befa9..7b47c3f 100644
--- a/Objects/methodobject.c
+++ b/Objects/methodobject.c
@@ -38,21 +38,31 @@ PERFORMANCE OF THIS SOFTWARE.
typedef struct {
PyObject_HEAD
PyMethodDef *m_ml;
- PyObject *m_self;
+ PyObject *m_self;
} PyCFunctionObject;
+static PyCFunctionObject *free_list = NULL;
+
PyObject *
PyCFunction_New(ml, self)
PyMethodDef *ml;
PyObject *self;
{
- PyCFunctionObject *op = PyObject_NEW(PyCFunctionObject,
- &PyCFunction_Type);
+ PyCFunctionObject *op;
+ op = free_list;
if (op != NULL) {
- op->m_ml = ml;
- Py_XINCREF(self);
- op->m_self = self;
+ free_list = (PyCFunctionObject *)(op->m_self);
+ op->ob_type = &PyCFunction_Type;
+ _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;
}
@@ -96,7 +106,8 @@ meth_dealloc(m)
PyCFunctionObject *m;
{
Py_XDECREF(m->m_self);
- free((char *)m);
+ m->m_self = (PyObject *)free_list;
+ free_list = m;
}
static PyObject *
@@ -267,3 +278,15 @@ Py_FindMethod(methods, self, name)
chain.link = NULL;
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);
+ }
+}