diff options
author | Inada Naoki <songofacandy@gmail.com> | 2019-07-26 15:05:50 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-26 15:05:50 +0900 |
commit | 3e54b575313c64f541e98216ed079fafed01ff5d (patch) | |
tree | 747f171a2d8d726cc97580c85ded8891a2bc41ae /Objects/classobject.c | |
parent | 76b645124b3aaa34bc664eece43707c01ef1b382 (diff) | |
download | cpython-git-3e54b575313c64f541e98216ed079fafed01ff5d.tar.gz |
bpo-37340: remove free_list for bound method objects (GH-14232)
Diffstat (limited to 'Objects/classobject.c')
-rw-r--r-- | Objects/classobject.c | 52 |
1 files changed, 5 insertions, 47 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c index 46525a737b..40cbeaa9f2 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -8,15 +8,6 @@ #define TP_DESCR_GET(t) ((t)->tp_descr_get) -/* Free list for method objects to safe malloc/free overhead - * The im_self element is used to chain the elements. - */ -static PyMethodObject *free_list; -static int numfree = 0; -#ifndef PyMethod_MAXFREELIST -#define PyMethod_MAXFREELIST 256 -#endif - _Py_IDENTIFIER(__name__); _Py_IDENTIFIER(__qualname__); @@ -103,21 +94,13 @@ method_vectorcall(PyObject *method, PyObject *const *args, PyObject * PyMethod_New(PyObject *func, PyObject *self) { - PyMethodObject *im; if (self == NULL) { PyErr_BadInternalCall(); return NULL; } - im = free_list; - if (im != NULL) { - free_list = (PyMethodObject *)(im->im_self); - (void)PyObject_INIT(im, &PyMethod_Type); - numfree--; - } - else { - im = PyObject_GC_New(PyMethodObject, &PyMethod_Type); - if (im == NULL) - return NULL; + PyMethodObject *im = PyObject_GC_New(PyMethodObject, &PyMethod_Type); + if (im == NULL) { + return NULL; } im->im_weakreflist = NULL; Py_INCREF(func); @@ -252,14 +235,7 @@ method_dealloc(PyMethodObject *im) PyObject_ClearWeakRefs((PyObject *)im); Py_DECREF(im->im_func); Py_XDECREF(im->im_self); - if (numfree < PyMethod_MAXFREELIST) { - im->im_self = (PyObject *)free_list; - free_list = im; - numfree++; - } - else { - PyObject_GC_Del(im); - } + PyObject_GC_Del(im); } static PyObject * @@ -395,16 +371,7 @@ PyTypeObject PyMethod_Type = { int PyMethod_ClearFreeList(void) { - int freelist_size = numfree; - - while (free_list) { - PyMethodObject *im = free_list; - free_list = (PyMethodObject *)(im->im_self); - PyObject_GC_Del(im); - numfree--; - } - assert(numfree == 0); - return freelist_size; + return 0; } void @@ -413,15 +380,6 @@ PyMethod_Fini(void) (void)PyMethod_ClearFreeList(); } -/* Print summary info about the state of the optimized allocator */ -void -_PyMethod_DebugMallocStats(FILE *out) -{ - _PyDebugAllocatorStats(out, - "free PyMethodObject", - numfree, sizeof(PyMethodObject)); -} - /* ------------------------------------------------------------------------ * instance method */ |