77#include "pycore_pystate.h"
88#include "structmember.h"
99
10- /* Free list for method objects to safe malloc/free overhead
11- * The m_self element is used to chain the objects.
12- */
13- static PyCFunctionObject * free_list = NULL ;
14- static int numfree = 0 ;
15- #ifndef PyCFunction_MAXFREELIST
16- #define PyCFunction_MAXFREELIST 256
17- #endif
18-
1910/* undefine macro trampoline to PyCFunction_NewEx */
2011#undef PyCFunction_New
2112
@@ -66,17 +57,10 @@ PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module)
6657 return NULL ;
6758 }
6859
69- PyCFunctionObject * op ;
70- op = free_list ;
71- if (op != NULL ) {
72- free_list = (PyCFunctionObject * )(op -> m_self );
73- (void )PyObject_INIT (op , & PyCFunction_Type );
74- numfree -- ;
75- }
76- else {
77- op = PyObject_GC_New (PyCFunctionObject , & PyCFunction_Type );
78- if (op == NULL )
79- return NULL ;
60+ PyCFunctionObject * op =
61+ PyObject_GC_New (PyCFunctionObject , & PyCFunction_Type );
62+ if (op == NULL ) {
63+ return NULL ;
8064 }
8165 op -> m_weakreflist = NULL ;
8266 op -> m_ml = ml ;
@@ -130,14 +114,7 @@ meth_dealloc(PyCFunctionObject *m)
130114 }
131115 Py_XDECREF (m -> m_self );
132116 Py_XDECREF (m -> m_module );
133- if (numfree < PyCFunction_MAXFREELIST ) {
134- m -> m_self = (PyObject * )free_list ;
135- free_list = m ;
136- numfree ++ ;
137- }
138- else {
139- PyObject_GC_Del (m );
140- }
117+ PyObject_GC_Del (m );
141118}
142119
143120static PyObject *
@@ -338,16 +315,7 @@ PyTypeObject PyCFunction_Type = {
338315int
339316PyCFunction_ClearFreeList (void )
340317{
341- int freelist_size = numfree ;
342-
343- while (free_list ) {
344- PyCFunctionObject * v = free_list ;
345- free_list = (PyCFunctionObject * )(v -> m_self );
346- PyObject_GC_Del (v );
347- numfree -- ;
348- }
349- assert (numfree == 0 );
350- return freelist_size ;
318+ return 0 ;
351319}
352320
353321void
@@ -356,15 +324,6 @@ PyCFunction_Fini(void)
356324 (void )PyCFunction_ClearFreeList ();
357325}
358326
359- /* Print summary info about the state of the optimized allocator */
360- void
361- _PyCFunction_DebugMallocStats (FILE * out )
362- {
363- _PyDebugAllocatorStats (out ,
364- "free PyCFunctionObject" ,
365- numfree , sizeof (PyCFunctionObject ));
366- }
367-
368327
369328/* Vectorcall functions for each of the PyCFunction calling conventions,
370329 * except for METH_VARARGS (possibly combined with METH_KEYWORDS) which
0 commit comments